@@ -100,7 +100,7 @@ static int uv_pin_shared(unsigned long paddr)
100100 *
101101 * @paddr: Absolute host address of page to be destroyed
102102 */
103- int uv_destroy_page (unsigned long paddr )
103+ static int uv_destroy_page (unsigned long paddr )
104104{
105105 struct uv_cb_cfs uvcb = {
106106 .header .cmd = UVC_CMD_DESTR_SEC_STOR ,
@@ -120,6 +120,22 @@ int uv_destroy_page(unsigned long paddr)
120120 return 0 ;
121121}
122122
123+ /*
124+ * The caller must already hold a reference to the page
125+ */
126+ int uv_destroy_owned_page (unsigned long paddr )
127+ {
128+ struct page * page = phys_to_page (paddr );
129+ int rc ;
130+
131+ get_page (page );
132+ rc = uv_destroy_page (paddr );
133+ if (!rc )
134+ clear_bit (PG_arch_1 , & page -> flags );
135+ put_page (page );
136+ return rc ;
137+ }
138+
123139/*
124140 * Requests the Ultravisor to encrypt a guest page and make it
125141 * accessible to the host for paging (export).
@@ -139,6 +155,22 @@ int uv_convert_from_secure(unsigned long paddr)
139155 return 0 ;
140156}
141157
158+ /*
159+ * The caller must already hold a reference to the page
160+ */
161+ int uv_convert_owned_from_secure (unsigned long paddr )
162+ {
163+ struct page * page = phys_to_page (paddr );
164+ int rc ;
165+
166+ get_page (page );
167+ rc = uv_convert_from_secure (paddr );
168+ if (!rc )
169+ clear_bit (PG_arch_1 , & page -> flags );
170+ put_page (page );
171+ return rc ;
172+ }
173+
142174/*
143175 * Calculate the expected ref_count for a page that would otherwise have no
144176 * further pins. This was cribbed from similar functions in other places in
@@ -165,7 +197,7 @@ static int make_secure_pte(pte_t *ptep, unsigned long addr,
165197{
166198 pte_t entry = READ_ONCE (* ptep );
167199 struct page * page ;
168- int expected , rc = 0 ;
200+ int expected , cc = 0 ;
169201
170202 if (!pte_present (entry ))
171203 return - ENXIO ;
@@ -181,12 +213,25 @@ static int make_secure_pte(pte_t *ptep, unsigned long addr,
181213 if (!page_ref_freeze (page , expected ))
182214 return - EBUSY ;
183215 set_bit (PG_arch_1 , & page -> flags );
184- rc = uv_call (0 , (u64 )uvcb );
216+ /*
217+ * If the UVC does not succeed or fail immediately, we don't want to
218+ * loop for long, or we might get stall notifications.
219+ * On the other hand, this is a complex scenario and we are holding a lot of
220+ * locks, so we can't easily sleep and reschedule. We try only once,
221+ * and if the UVC returned busy or partial completion, we return
222+ * -EAGAIN and we let the callers deal with it.
223+ */
224+ cc = __uv_call (0 , (u64 )uvcb );
185225 page_ref_unfreeze (page , expected );
186- /* Return -ENXIO if the page was not mapped, -EINVAL otherwise */
187- if (rc )
188- rc = uvcb -> rc == 0x10a ? - ENXIO : - EINVAL ;
189- return rc ;
226+ /*
227+ * Return -ENXIO if the page was not mapped, -EINVAL for other errors.
228+ * If busy or partially completed, return -EAGAIN.
229+ */
230+ if (cc == UVC_CC_OK )
231+ return 0 ;
232+ else if (cc == UVC_CC_BUSY || cc == UVC_CC_PARTIAL )
233+ return - EAGAIN ;
234+ return uvcb -> rc == 0x10a ? - ENXIO : - EINVAL ;
190235}
191236
192237/*
@@ -212,7 +257,7 @@ int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb)
212257 uaddr = __gmap_translate (gmap , gaddr );
213258 if (IS_ERR_VALUE (uaddr ))
214259 goto out ;
215- vma = find_vma (gmap -> mm , uaddr );
260+ vma = vma_lookup (gmap -> mm , uaddr );
216261 if (!vma )
217262 goto out ;
218263 /*
@@ -239,6 +284,10 @@ int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb)
239284 mmap_read_unlock (gmap -> mm );
240285
241286 if (rc == - EAGAIN ) {
287+ /*
288+ * If we are here because the UVC returned busy or partial
289+ * completion, this is just a useless check, but it is safe.
290+ */
242291 wait_on_page_writeback (page );
243292 } else if (rc == - EBUSY ) {
244293 /*
0 commit comments