Skip to content

Commit 107e899

Browse files
committed
mm/hmm: define the pre-processor related parts of hmm.h even if disabled
Only the function calls are stubbed out with static inlines that always fail. This is the standard way to write a header for an optional component and makes it easier for drivers that only optionally need HMM_MIRROR. Link: https://lore.kernel.org/r/20191112202231.3856-5-jgg@ziepe.ca Reviewed-by: Jérôme Glisse <jglisse@redhat.com> Tested-by: Ralph Campbell <rcampbell@nvidia.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 04ec32f commit 107e899

2 files changed

Lines changed: 47 additions & 13 deletions

File tree

‎include/linux/hmm.h‎

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@
6262
#include <linux/kconfig.h>
6363
#include <asm/pgtable.h>
6464

65-
#ifdef CONFIG_HMM_MIRROR
66-
6765
#include <linux/device.h>
6866
#include <linux/migrate.h>
6967
#include <linux/memremap.h>
@@ -374,6 +372,15 @@ struct hmm_mirror {
374372
struct list_head list;
375373
};
376374

375+
/*
376+
* Retry fault if non-blocking, drop mmap_sem and return -EAGAIN in that case.
377+
*/
378+
#define HMM_FAULT_ALLOW_RETRY (1 << 0)
379+
380+
/* Don't fault in missing PTEs, just snapshot the current state. */
381+
#define HMM_FAULT_SNAPSHOT (1 << 1)
382+
383+
#ifdef CONFIG_HMM_MIRROR
377384
int hmm_mirror_register(struct hmm_mirror *mirror, struct mm_struct *mm);
378385
void hmm_mirror_unregister(struct hmm_mirror *mirror);
379386

@@ -383,14 +390,6 @@ void hmm_mirror_unregister(struct hmm_mirror *mirror);
383390
int hmm_range_register(struct hmm_range *range, struct hmm_mirror *mirror);
384391
void hmm_range_unregister(struct hmm_range *range);
385392

386-
/*
387-
* Retry fault if non-blocking, drop mmap_sem and return -EAGAIN in that case.
388-
*/
389-
#define HMM_FAULT_ALLOW_RETRY (1 << 0)
390-
391-
/* Don't fault in missing PTEs, just snapshot the current state. */
392-
#define HMM_FAULT_SNAPSHOT (1 << 1)
393-
394393
long hmm_range_fault(struct hmm_range *range, unsigned int flags);
395394

396395
long hmm_range_dma_map(struct hmm_range *range,
@@ -401,6 +400,44 @@ long hmm_range_dma_unmap(struct hmm_range *range,
401400
struct device *device,
402401
dma_addr_t *daddrs,
403402
bool dirty);
403+
#else
404+
int hmm_mirror_register(struct hmm_mirror *mirror, struct mm_struct *mm)
405+
{
406+
return -EOPNOTSUPP;
407+
}
408+
409+
void hmm_mirror_unregister(struct hmm_mirror *mirror)
410+
{
411+
}
412+
413+
int hmm_range_register(struct hmm_range *range, struct hmm_mirror *mirror)
414+
{
415+
return -EOPNOTSUPP;
416+
}
417+
418+
void hmm_range_unregister(struct hmm_range *range)
419+
{
420+
}
421+
422+
static inline long hmm_range_fault(struct hmm_range *range, unsigned int flags)
423+
{
424+
return -EOPNOTSUPP;
425+
}
426+
427+
static inline long hmm_range_dma_map(struct hmm_range *range,
428+
struct device *device, dma_addr_t *daddrs,
429+
unsigned int flags)
430+
{
431+
return -EOPNOTSUPP;
432+
}
433+
434+
static inline long hmm_range_dma_unmap(struct hmm_range *range,
435+
struct device *device,
436+
dma_addr_t *daddrs, bool dirty)
437+
{
438+
return -EOPNOTSUPP;
439+
}
440+
#endif
404441

405442
/*
406443
* HMM_RANGE_DEFAULT_TIMEOUT - default timeout (ms) when waiting for a range
@@ -411,6 +448,4 @@ long hmm_range_dma_unmap(struct hmm_range *range,
411448
*/
412449
#define HMM_RANGE_DEFAULT_TIMEOUT 1000
413450

414-
#endif /* IS_ENABLED(CONFIG_HMM_MIRROR) */
415-
416451
#endif /* LINUX_HMM_H */

‎kernel/fork.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include <linux/binfmts.h>
4141
#include <linux/mman.h>
4242
#include <linux/mmu_notifier.h>
43-
#include <linux/hmm.h>
4443
#include <linux/fs.h>
4544
#include <linux/mm.h>
4645
#include <linux/vmacache.h>

0 commit comments

Comments
 (0)