Skip to content

Commit 2d9900f

Browse files
committed
afs: Fix dirty-region encoding on ppc32 with 64K pages
The dirty region bounds stored in page->private on an afs page are 15 bits on a 32-bit box and can, at most, represent a range of up to 32K within a 32K page with a resolution of 1 byte. This is a problem for powerpc32 with 64K pages enabled. Further, transparent huge pages may get up to 2M, which will be a problem for the afs filesystem on all 32-bit arches in the future. Fix this by decreasing the resolution. For the moment, a 64K page will have a resolution determined from PAGE_SIZE. In the future, the page will need to be passed in to the helper functions so that the page size can be assessed and the resolution determined dynamically. Note that this might not be the ideal way to handle this, since it may allow some leakage of undirtied zero bytes to the server's copy in the case of a 3rd-party conflict. Fixing that would require a separately allocated record and is a more complicated fix. Fixes: 4343d00 ("afs: Get rid of the afs_writeback record") Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
1 parent f86726a commit 2d9900f

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

‎fs/afs/internal.h‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,8 @@ struct afs_vnode_cache_aux {
861861
/*
862862
* We use page->private to hold the amount of the page that we've written to,
863863
* splitting the field into two parts. However, we need to represent a range
864-
* 0...PAGE_SIZE inclusive, so we can't support 64K pages on a 32-bit system.
864+
* 0...PAGE_SIZE, so we reduce the resolution if the size of the page
865+
* exceeds what we can encode.
865866
*/
866867
#ifdef CONFIG_64BIT
867868
#define __AFS_PAGE_PRIV_MASK 0x7fffffffUL
@@ -873,19 +874,34 @@ struct afs_vnode_cache_aux {
873874
#define __AFS_PAGE_PRIV_MMAPPED 0x8000UL
874875
#endif
875876

877+
static inline unsigned int afs_page_dirty_resolution(void)
878+
{
879+
int shift = PAGE_SHIFT - (__AFS_PAGE_PRIV_SHIFT - 1);
880+
return (shift > 0) ? shift : 0;
881+
}
882+
876883
static inline size_t afs_page_dirty_from(unsigned long priv)
877884
{
878-
return priv & __AFS_PAGE_PRIV_MASK;
885+
unsigned long x = priv & __AFS_PAGE_PRIV_MASK;
886+
887+
/* The lower bound is inclusive */
888+
return x << afs_page_dirty_resolution();
879889
}
880890

881891
static inline size_t afs_page_dirty_to(unsigned long priv)
882892
{
883-
return ((priv >> __AFS_PAGE_PRIV_SHIFT) & __AFS_PAGE_PRIV_MASK) + 1;
893+
unsigned long x = (priv >> __AFS_PAGE_PRIV_SHIFT) & __AFS_PAGE_PRIV_MASK;
894+
895+
/* The upper bound is immediately beyond the region */
896+
return (x + 1) << afs_page_dirty_resolution();
884897
}
885898

886899
static inline unsigned long afs_page_dirty(size_t from, size_t to)
887900
{
888-
return ((unsigned long)(to - 1) << __AFS_PAGE_PRIV_SHIFT) | from;
901+
unsigned int res = afs_page_dirty_resolution();
902+
from >>= res;
903+
to = (to - 1) >> res;
904+
return (to << __AFS_PAGE_PRIV_SHIFT) | from;
889905
}
890906

891907
static inline unsigned long afs_page_dirty_mmapped(unsigned long priv)

‎fs/afs/write.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ int afs_write_begin(struct file *file, struct address_space *mapping,
9090
_enter("{%llx:%llu},{%lx},%u,%u",
9191
vnode->fid.vid, vnode->fid.vnode, index, from, to);
9292

93-
/* We want to store information about how much of a page is altered in
94-
* page->private.
95-
*/
96-
BUILD_BUG_ON(PAGE_SIZE - 1 > __AFS_PAGE_PRIV_MASK && sizeof(page->private) < 8);
97-
9893
page = grab_cache_page_write_begin(mapping, index, flags);
9994
if (!page)
10095
return -ENOMEM;

0 commit comments

Comments
 (0)