Skip to content

Commit 27e6a24

Browse files
committed
mm, virt: merge AS_UNMOVABLE and AS_INACCESSIBLE
The flags AS_UNMOVABLE and AS_INACCESSIBLE were both added just for guest_memfd; AS_UNMOVABLE is already in existing versions of Linux, while AS_INACCESSIBLE was acked for inclusion in 6.11. But really, they are the same thing: only guest_memfd uses them, at least for now, and guest_memfd pages are unmovable because they should not be accessed by the CPU. So merge them into one; use the AS_INACCESSIBLE name which is more comprehensive. At the same time, this fixes an embarrassing bug where AS_INACCESSIBLE was used as a bit mask, despite it being just a bit index. The bug was mostly benign, because AS_INACCESSIBLE's bit representation (1010) corresponded to setting AS_UNEVICTABLE (which is already set) and AS_ENOSPC (except no async writes can happen on the guest_memfd). So the AS_INACCESSIBLE flag simply had no effect. Fixes: 1d23040 ("KVM: guest_memfd: Use AS_INACCESSIBLE when creating guest_memfd inode") Fixes: c72ceaf ("mm: Introduce AS_INACCESSIBLE for encrypted/confidential memory") Cc: [email protected] Acked-by: Vlastimil Babka <[email protected]> Acked-by: David Hildenbrand <[email protected]> Tested-by: Michael Roth <[email protected]> Reviewed-by: Michael Roth <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 02b0d3b commit 27e6a24

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

include/linux/pagemap.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ enum mapping_flags {
208208
AS_RELEASE_ALWAYS, /* Call ->release_folio(), even if no private data */
209209
AS_STABLE_WRITES, /* must wait for writeback before modifying
210210
folio contents */
211-
AS_UNMOVABLE, /* The mapping cannot be moved, ever */
212-
AS_INACCESSIBLE, /* Do not attempt direct R/W access to the mapping */
211+
AS_INACCESSIBLE, /* Do not attempt direct R/W access to the mapping,
212+
including to move the mapping */
213213
};
214214

215215
/**
@@ -310,20 +310,20 @@ static inline void mapping_clear_stable_writes(struct address_space *mapping)
310310
clear_bit(AS_STABLE_WRITES, &mapping->flags);
311311
}
312312

313-
static inline void mapping_set_unmovable(struct address_space *mapping)
313+
static inline void mapping_set_inaccessible(struct address_space *mapping)
314314
{
315315
/*
316-
* It's expected unmovable mappings are also unevictable. Compaction
316+
* It's expected inaccessible mappings are also unevictable. Compaction
317317
* migrate scanner (isolate_migratepages_block()) relies on this to
318318
* reduce page locking.
319319
*/
320320
set_bit(AS_UNEVICTABLE, &mapping->flags);
321-
set_bit(AS_UNMOVABLE, &mapping->flags);
321+
set_bit(AS_INACCESSIBLE, &mapping->flags);
322322
}
323323

324-
static inline bool mapping_unmovable(struct address_space *mapping)
324+
static inline bool mapping_inaccessible(struct address_space *mapping)
325325
{
326-
return test_bit(AS_UNMOVABLE, &mapping->flags);
326+
return test_bit(AS_INACCESSIBLE, &mapping->flags);
327327
}
328328

329329
static inline gfp_t mapping_gfp_mask(struct address_space * mapping)

mm/compaction.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,22 +1172,22 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
11721172
if (((mode & ISOLATE_ASYNC_MIGRATE) && is_dirty) ||
11731173
(mapping && is_unevictable)) {
11741174
bool migrate_dirty = true;
1175-
bool is_unmovable;
1175+
bool is_inaccessible;
11761176

11771177
/*
11781178
* Only folios without mappings or that have
11791179
* a ->migrate_folio callback are possible to migrate
11801180
* without blocking.
11811181
*
1182-
* Folios from unmovable mappings are not migratable.
1182+
* Folios from inaccessible mappings are not migratable.
11831183
*
11841184
* However, we can be racing with truncation, which can
11851185
* free the mapping that we need to check. Truncation
11861186
* holds the folio lock until after the folio is removed
11871187
* from the page so holding it ourselves is sufficient.
11881188
*
1189-
* To avoid locking the folio just to check unmovable,
1190-
* assume every unmovable folio is also unevictable,
1189+
* To avoid locking the folio just to check inaccessible,
1190+
* assume every inaccessible folio is also unevictable,
11911191
* which is a cheaper test. If our assumption goes
11921192
* wrong, it's not a correctness bug, just potentially
11931193
* wasted cycles.
@@ -1200,9 +1200,9 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
12001200
migrate_dirty = !mapping ||
12011201
mapping->a_ops->migrate_folio;
12021202
}
1203-
is_unmovable = mapping && mapping_unmovable(mapping);
1203+
is_inaccessible = mapping && mapping_inaccessible(mapping);
12041204
folio_unlock(folio);
1205-
if (!migrate_dirty || is_unmovable)
1205+
if (!migrate_dirty || is_inaccessible)
12061206
goto isolate_fail_put;
12071207
}
12081208

mm/migrate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ static int move_to_new_folio(struct folio *dst, struct folio *src,
965965

966966
if (!mapping)
967967
rc = migrate_folio(mapping, dst, src, mode);
968-
else if (mapping_unmovable(mapping))
968+
else if (mapping_inaccessible(mapping))
969969
rc = -EOPNOTSUPP;
970970
else if (mapping->a_ops->migrate_folio)
971971
/*

mm/truncate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end)
233233
* doing a complex calculation here, and then doing the zeroing
234234
* anyway if the page split fails.
235235
*/
236-
if (!(folio->mapping->flags & AS_INACCESSIBLE))
236+
if (!mapping_inaccessible(folio->mapping))
237237
folio_zero_range(folio, offset, length);
238238

239239
if (folio_has_private(folio))

virt/kvm/guest_memfd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,10 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags)
416416
inode->i_private = (void *)(unsigned long)flags;
417417
inode->i_op = &kvm_gmem_iops;
418418
inode->i_mapping->a_ops = &kvm_gmem_aops;
419-
inode->i_mapping->flags |= AS_INACCESSIBLE;
420419
inode->i_mode |= S_IFREG;
421420
inode->i_size = size;
422421
mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER);
423-
mapping_set_unmovable(inode->i_mapping);
422+
mapping_set_inaccessible(inode->i_mapping);
424423
/* Unmovable mappings are supposed to be marked unevictable as well. */
425424
WARN_ON_ONCE(!mapping_unevictable(inode->i_mapping));
426425

0 commit comments

Comments
 (0)