* [PATCH 1/1] mm/kasan: use {READ,WRITE}_MODE not true,false
@ 2016-06-05 11:11 seokhoon.yoon
2016-06-05 12:49 ` Dmitry Vyukov
0 siblings, 1 reply; 4+ messages in thread
From: seokhoon.yoon @ 2016-06-05 11:11 UTC (permalink / raw)
To: Andrey Ryabinin; +Cc: Dmitry Vyukov, kasan-dev, linux-mm, iamyooon, sh.yoon
When Kasan tell memory access is write or not, use true or false.
This expression is simple and convenient.
But I think it is possible to more readable. and so change it.
Signed-off-by: seokhoon.yoon <iamyooon@gmail.com>
---
mm/kasan/kasan.c | 32 ++++++++++++++++----------------
mm/kasan/kasan.h | 12 ++++++++++--
mm/kasan/report.c | 16 ++++++++--------
3 files changed, 34 insertions(+), 26 deletions(-)
diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c
index 18b6a2b..642d936 100644
--- a/mm/kasan/kasan.c
+++ b/mm/kasan/kasan.c
@@ -274,7 +274,7 @@ static __always_inline bool memory_is_poisoned(unsigned long addr, size_t size)
}
static __always_inline void check_memory_region_inline(unsigned long addr,
- size_t size, bool write,
+ size_t size, enum acc_type type,
unsigned long ret_ip)
{
if (unlikely(size == 0))
@@ -282,39 +282,39 @@ static __always_inline void check_memory_region_inline(unsigned long addr,
if (unlikely((void *)addr <
kasan_shadow_to_mem((void *)KASAN_SHADOW_START))) {
- kasan_report(addr, size, write, ret_ip);
+ kasan_report(addr, size, type, ret_ip);
return;
}
if (likely(!memory_is_poisoned(addr, size)))
return;
- kasan_report(addr, size, write, ret_ip);
+ kasan_report(addr, size, type, ret_ip);
}
static void check_memory_region(unsigned long addr,
- size_t size, bool write,
+ size_t size, enum acc_type type,
unsigned long ret_ip)
{
- check_memory_region_inline(addr, size, write, ret_ip);
+ check_memory_region_inline(addr, size, type, ret_ip);
}
void kasan_check_read(const void *p, unsigned int size)
{
- check_memory_region((unsigned long)p, size, false, _RET_IP_);
+ check_memory_region((unsigned long)p, size, READ_MODE, _RET_IP_);
}
EXPORT_SYMBOL(kasan_check_read);
void kasan_check_write(const void *p, unsigned int size)
{
- check_memory_region((unsigned long)p, size, true, _RET_IP_);
+ check_memory_region((unsigned long)p, size, WRITE_MODE, _RET_IP_);
}
EXPORT_SYMBOL(kasan_check_write);
#undef memset
void *memset(void *addr, int c, size_t len)
{
- check_memory_region((unsigned long)addr, len, true, _RET_IP_);
+ check_memory_region((unsigned long)addr, len, WRITE_MODE, _RET_IP_);
return __memset(addr, c, len);
}
@@ -322,8 +322,8 @@ void *memset(void *addr, int c, size_t len)
#undef memmove
void *memmove(void *dest, const void *src, size_t len)
{
- check_memory_region((unsigned long)src, len, false, _RET_IP_);
- check_memory_region((unsigned long)dest, len, true, _RET_IP_);
+ check_memory_region((unsigned long)src, len, READ_MODE, _RET_IP_);
+ check_memory_region((unsigned long)dest, len, WRITE_MODE, _RET_IP_);
return __memmove(dest, src, len);
}
@@ -331,8 +331,8 @@ void *memmove(void *dest, const void *src, size_t len)
#undef memcpy
void *memcpy(void *dest, const void *src, size_t len)
{
- check_memory_region((unsigned long)src, len, false, _RET_IP_);
- check_memory_region((unsigned long)dest, len, true, _RET_IP_);
+ check_memory_region((unsigned long)src, len, READ_MODE, _RET_IP_);
+ check_memory_region((unsigned long)dest, len, WRITE_MODE, _RET_IP_);
return __memcpy(dest, src, len);
}
@@ -709,7 +709,7 @@ EXPORT_SYMBOL(__asan_unregister_globals);
#define DEFINE_ASAN_LOAD_STORE(size) \
void __asan_load##size(unsigned long addr) \
{ \
- check_memory_region_inline(addr, size, false, _RET_IP_);\
+ check_memory_region_inline(addr, size, READ_MODE, _RET_IP_);\
} \
EXPORT_SYMBOL(__asan_load##size); \
__alias(__asan_load##size) \
@@ -717,7 +717,7 @@ EXPORT_SYMBOL(__asan_unregister_globals);
EXPORT_SYMBOL(__asan_load##size##_noabort); \
void __asan_store##size(unsigned long addr) \
{ \
- check_memory_region_inline(addr, size, true, _RET_IP_); \
+ check_memory_region_inline(addr, size, WRITE_MODE, _RET_IP_);\
} \
EXPORT_SYMBOL(__asan_store##size); \
__alias(__asan_store##size) \
@@ -732,7 +732,7 @@ DEFINE_ASAN_LOAD_STORE(16);
void __asan_loadN(unsigned long addr, size_t size)
{
- check_memory_region(addr, size, false, _RET_IP_);
+ check_memory_region(addr, size, READ_MODE, _RET_IP_);
}
EXPORT_SYMBOL(__asan_loadN);
@@ -742,7 +742,7 @@ EXPORT_SYMBOL(__asan_loadN_noabort);
void __asan_storeN(unsigned long addr, size_t size)
{
- check_memory_region(addr, size, true, _RET_IP_);
+ check_memory_region(addr, size, WRITE_MODE, _RET_IP_);
}
EXPORT_SYMBOL(__asan_storeN);
diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
index 7f7ac51..47cb58c 100644
--- a/mm/kasan/kasan.h
+++ b/mm/kasan/kasan.h
@@ -27,11 +27,19 @@
#define KASAN_ABI_VERSION 1
#endif
+/*
+ * Distinguish memory access
+ */
+enum acc_type {
+ READ_MODE,
+ WRITE_MODE
+};
+
struct kasan_access_info {
const void *access_addr;
const void *first_bad_addr;
size_t access_size;
- bool is_write;
+ enum acc_type access_type;
unsigned long ip;
};
@@ -109,7 +117,7 @@ static inline bool kasan_report_enabled(void)
}
void kasan_report(unsigned long addr, size_t size,
- bool is_write, unsigned long ip);
+ enum acc_type type, unsigned long ip);
#ifdef CONFIG_SLAB
void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache);
diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index b3c122d..e0bee22 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -96,7 +96,7 @@ static void print_error_description(struct kasan_access_info *info)
bug_type, (void *)info->ip,
info->access_addr);
pr_err("%s of size %zu by task %s/%d\n",
- info->is_write ? "Write" : "Read",
+ info->access_type == WRITE_MODE ? "Write" : "Read",
info->access_size, current->comm, task_pid_nr(current));
}
@@ -267,7 +267,7 @@ static void kasan_report_error(struct kasan_access_info *info)
pr_err("BUG: KASAN: %s on address %p\n",
bug_type, info->access_addr);
pr_err("%s of size %zu by task %s/%d\n",
- info->is_write ? "Write" : "Read",
+ info->access_type == WRITE_MODE ? "Write" : "Read",
info->access_size, current->comm,
task_pid_nr(current));
dump_stack();
@@ -283,7 +283,7 @@ static void kasan_report_error(struct kasan_access_info *info)
}
void kasan_report(unsigned long addr, size_t size,
- bool is_write, unsigned long ip)
+ enum acc_type type, unsigned long ip)
{
struct kasan_access_info info;
@@ -292,7 +292,7 @@ void kasan_report(unsigned long addr, size_t size,
info.access_addr = (void *)addr;
info.access_size = size;
- info.is_write = is_write;
+ info.access_type = type;
info.ip = ip;
kasan_report_error(&info);
@@ -302,14 +302,14 @@ void kasan_report(unsigned long addr, size_t size,
#define DEFINE_ASAN_REPORT_LOAD(size) \
void __asan_report_load##size##_noabort(unsigned long addr) \
{ \
- kasan_report(addr, size, false, _RET_IP_); \
+ kasan_report(addr, size, READ_MODE, _RET_IP_); \
} \
EXPORT_SYMBOL(__asan_report_load##size##_noabort)
#define DEFINE_ASAN_REPORT_STORE(size) \
void __asan_report_store##size##_noabort(unsigned long addr) \
{ \
- kasan_report(addr, size, true, _RET_IP_); \
+ kasan_report(addr, size, WRITE_MODE, _RET_IP_); \
} \
EXPORT_SYMBOL(__asan_report_store##size##_noabort)
@@ -326,12 +326,12 @@ DEFINE_ASAN_REPORT_STORE(16);
void __asan_report_load_n_noabort(unsigned long addr, size_t size)
{
- kasan_report(addr, size, false, _RET_IP_);
+ kasan_report(addr, size, READ_MODE, _RET_IP_);
}
EXPORT_SYMBOL(__asan_report_load_n_noabort);
void __asan_report_store_n_noabort(unsigned long addr, size_t size)
{
- kasan_report(addr, size, true, _RET_IP_);
+ kasan_report(addr, size, WRITE_MODE, _RET_IP_);
}
EXPORT_SYMBOL(__asan_report_store_n_noabort);
--
1.9.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/1] mm/kasan: use {READ,WRITE}_MODE not true,false 2016-06-05 11:11 [PATCH 1/1] mm/kasan: use {READ,WRITE}_MODE not true,false seokhoon.yoon @ 2016-06-05 12:49 ` Dmitry Vyukov 2016-06-05 23:08 ` SeokHoon Yoon 0 siblings, 1 reply; 4+ messages in thread From: Dmitry Vyukov @ 2016-06-05 12:49 UTC (permalink / raw) To: seokhoon.yoon; +Cc: Andrey Ryabinin, kasan-dev, linux-mm, sh.yoon On Sun, Jun 5, 2016 at 1:11 PM, seokhoon.yoon <iamyooon@gmail.com> wrote: > When Kasan tell memory access is write or not, use true or false. > This expression is simple and convenient. > > But I think it is possible to more readable. and so change it. > > Signed-off-by: seokhoon.yoon <iamyooon@gmail.com> > --- > mm/kasan/kasan.c | 32 ++++++++++++++++---------------- > mm/kasan/kasan.h | 12 ++++++++++-- > mm/kasan/report.c | 16 ++++++++-------- > 3 files changed, 34 insertions(+), 26 deletions(-) > > diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c > index 18b6a2b..642d936 100644 > --- a/mm/kasan/kasan.c > +++ b/mm/kasan/kasan.c > @@ -274,7 +274,7 @@ static __always_inline bool memory_is_poisoned(unsigned long addr, size_t size) > } > > static __always_inline void check_memory_region_inline(unsigned long addr, > - size_t size, bool write, > + size_t size, enum acc_type type, > unsigned long ret_ip) > { > if (unlikely(size == 0)) > @@ -282,39 +282,39 @@ static __always_inline void check_memory_region_inline(unsigned long addr, > > if (unlikely((void *)addr < > kasan_shadow_to_mem((void *)KASAN_SHADOW_START))) { > - kasan_report(addr, size, write, ret_ip); > + kasan_report(addr, size, type, ret_ip); > return; > } > > if (likely(!memory_is_poisoned(addr, size))) > return; > > - kasan_report(addr, size, write, ret_ip); > + kasan_report(addr, size, type, ret_ip); > } > > static void check_memory_region(unsigned long addr, > - size_t size, bool write, > + size_t size, enum acc_type type, > unsigned long ret_ip) > { > - check_memory_region_inline(addr, size, write, ret_ip); > + check_memory_region_inline(addr, size, type, ret_ip); > } > > void kasan_check_read(const void *p, unsigned int size) > { > - check_memory_region((unsigned long)p, size, false, _RET_IP_); > + check_memory_region((unsigned long)p, size, READ_MODE, _RET_IP_); > } > EXPORT_SYMBOL(kasan_check_read); > > void kasan_check_write(const void *p, unsigned int size) > { > - check_memory_region((unsigned long)p, size, true, _RET_IP_); > + check_memory_region((unsigned long)p, size, WRITE_MODE, _RET_IP_); > } > EXPORT_SYMBOL(kasan_check_write); > > #undef memset > void *memset(void *addr, int c, size_t len) > { > - check_memory_region((unsigned long)addr, len, true, _RET_IP_); > + check_memory_region((unsigned long)addr, len, WRITE_MODE, _RET_IP_); > > return __memset(addr, c, len); > } > @@ -322,8 +322,8 @@ void *memset(void *addr, int c, size_t len) > #undef memmove > void *memmove(void *dest, const void *src, size_t len) > { > - check_memory_region((unsigned long)src, len, false, _RET_IP_); > - check_memory_region((unsigned long)dest, len, true, _RET_IP_); > + check_memory_region((unsigned long)src, len, READ_MODE, _RET_IP_); > + check_memory_region((unsigned long)dest, len, WRITE_MODE, _RET_IP_); > > return __memmove(dest, src, len); > } > @@ -331,8 +331,8 @@ void *memmove(void *dest, const void *src, size_t len) > #undef memcpy > void *memcpy(void *dest, const void *src, size_t len) > { > - check_memory_region((unsigned long)src, len, false, _RET_IP_); > - check_memory_region((unsigned long)dest, len, true, _RET_IP_); > + check_memory_region((unsigned long)src, len, READ_MODE, _RET_IP_); > + check_memory_region((unsigned long)dest, len, WRITE_MODE, _RET_IP_); > > return __memcpy(dest, src, len); > } > @@ -709,7 +709,7 @@ EXPORT_SYMBOL(__asan_unregister_globals); > #define DEFINE_ASAN_LOAD_STORE(size) \ > void __asan_load##size(unsigned long addr) \ > { \ > - check_memory_region_inline(addr, size, false, _RET_IP_);\ > + check_memory_region_inline(addr, size, READ_MODE, _RET_IP_);\ > } \ > EXPORT_SYMBOL(__asan_load##size); \ > __alias(__asan_load##size) \ > @@ -717,7 +717,7 @@ EXPORT_SYMBOL(__asan_unregister_globals); > EXPORT_SYMBOL(__asan_load##size##_noabort); \ > void __asan_store##size(unsigned long addr) \ > { \ > - check_memory_region_inline(addr, size, true, _RET_IP_); \ > + check_memory_region_inline(addr, size, WRITE_MODE, _RET_IP_);\ > } \ > EXPORT_SYMBOL(__asan_store##size); \ > __alias(__asan_store##size) \ > @@ -732,7 +732,7 @@ DEFINE_ASAN_LOAD_STORE(16); > > void __asan_loadN(unsigned long addr, size_t size) > { > - check_memory_region(addr, size, false, _RET_IP_); > + check_memory_region(addr, size, READ_MODE, _RET_IP_); > } > EXPORT_SYMBOL(__asan_loadN); > > @@ -742,7 +742,7 @@ EXPORT_SYMBOL(__asan_loadN_noabort); > > void __asan_storeN(unsigned long addr, size_t size) > { > - check_memory_region(addr, size, true, _RET_IP_); > + check_memory_region(addr, size, WRITE_MODE, _RET_IP_); > } > EXPORT_SYMBOL(__asan_storeN); > > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > index 7f7ac51..47cb58c 100644 > --- a/mm/kasan/kasan.h > +++ b/mm/kasan/kasan.h > @@ -27,11 +27,19 @@ > #define KASAN_ABI_VERSION 1 > #endif > > +/* > + * Distinguish memory access > + */ > +enum acc_type { > + READ_MODE, > + WRITE_MODE > +}; > + > struct kasan_access_info { > const void *access_addr; > const void *first_bad_addr; > size_t access_size; > - bool is_write; > + enum acc_type access_type; > unsigned long ip; > }; > > @@ -109,7 +117,7 @@ static inline bool kasan_report_enabled(void) > } > > void kasan_report(unsigned long addr, size_t size, > - bool is_write, unsigned long ip); > + enum acc_type type, unsigned long ip); > > #ifdef CONFIG_SLAB > void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache); > diff --git a/mm/kasan/report.c b/mm/kasan/report.c > index b3c122d..e0bee22 100644 > --- a/mm/kasan/report.c > +++ b/mm/kasan/report.c > @@ -96,7 +96,7 @@ static void print_error_description(struct kasan_access_info *info) > bug_type, (void *)info->ip, > info->access_addr); > pr_err("%s of size %zu by task %s/%d\n", > - info->is_write ? "Write" : "Read", > + info->access_type == WRITE_MODE ? "Write" : "Read", > info->access_size, current->comm, task_pid_nr(current)); > } > > @@ -267,7 +267,7 @@ static void kasan_report_error(struct kasan_access_info *info) > pr_err("BUG: KASAN: %s on address %p\n", > bug_type, info->access_addr); > pr_err("%s of size %zu by task %s/%d\n", > - info->is_write ? "Write" : "Read", > + info->access_type == WRITE_MODE ? "Write" : "Read", > info->access_size, current->comm, > task_pid_nr(current)); > dump_stack(); > @@ -283,7 +283,7 @@ static void kasan_report_error(struct kasan_access_info *info) > } > > void kasan_report(unsigned long addr, size_t size, > - bool is_write, unsigned long ip) > + enum acc_type type, unsigned long ip) > { > struct kasan_access_info info; > > @@ -292,7 +292,7 @@ void kasan_report(unsigned long addr, size_t size, > > info.access_addr = (void *)addr; > info.access_size = size; > - info.is_write = is_write; > + info.access_type = type; > info.ip = ip; > > kasan_report_error(&info); > @@ -302,14 +302,14 @@ void kasan_report(unsigned long addr, size_t size, > #define DEFINE_ASAN_REPORT_LOAD(size) \ > void __asan_report_load##size##_noabort(unsigned long addr) \ > { \ > - kasan_report(addr, size, false, _RET_IP_); \ > + kasan_report(addr, size, READ_MODE, _RET_IP_); \ > } \ > EXPORT_SYMBOL(__asan_report_load##size##_noabort) > > #define DEFINE_ASAN_REPORT_STORE(size) \ > void __asan_report_store##size##_noabort(unsigned long addr) \ > { \ > - kasan_report(addr, size, true, _RET_IP_); \ > + kasan_report(addr, size, WRITE_MODE, _RET_IP_); \ > } \ > EXPORT_SYMBOL(__asan_report_store##size##_noabort) > > @@ -326,12 +326,12 @@ DEFINE_ASAN_REPORT_STORE(16); > > void __asan_report_load_n_noabort(unsigned long addr, size_t size) > { > - kasan_report(addr, size, false, _RET_IP_); > + kasan_report(addr, size, READ_MODE, _RET_IP_); > } > EXPORT_SYMBOL(__asan_report_load_n_noabort); > > void __asan_report_store_n_noabort(unsigned long addr, size_t size) > { > - kasan_report(addr, size, true, _RET_IP_); > + kasan_report(addr, size, WRITE_MODE, _RET_IP_); > } > EXPORT_SYMBOL(__asan_report_store_n_noabort); Hello seokhoon.yoon, Where exactly do you hit readability problems? I would say that the only problematic place is where we initialize the value: kasan_report(addr, size, true, _RET_IP_); check_memory_region(addr, size, true, _RET_IP_); Here it is really difficult to say what true/false mean. Even if you know that it is access type, you don't necessary remember if true means write or read. That could be solved by adding comments: kasan_report(addr, size, /* write = */ true, _RET_IP_); In all other places one sees that we are talking about "write". -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] mm/kasan: use {READ,WRITE}_MODE not true,false 2016-06-05 12:49 ` Dmitry Vyukov @ 2016-06-05 23:08 ` SeokHoon Yoon 2016-06-06 14:33 ` Dmitry Vyukov 0 siblings, 1 reply; 4+ messages in thread From: SeokHoon Yoon @ 2016-06-05 23:08 UTC (permalink / raw) To: Dmitry Vyukov; +Cc: Andrey Ryabinin, kasan-dev, linux-mm, sh.yoon [-- Attachment #1: Type: text/plain, Size: 11167 bytes --] 2016-06-05 21:49 GMT+09:00 Dmitry Vyukov <dvyukov@google.com>: > On Sun, Jun 5, 2016 at 1:11 PM, seokhoon.yoon <iamyooon@gmail.com> wrote: > > When Kasan tell memory access is write or not, use true or false. > > This expression is simple and convenient. > > > > But I think it is possible to more readable. and so change it. > > > > Signed-off-by: seokhoon.yoon <iamyooon@gmail.com> > > --- > > mm/kasan/kasan.c | 32 ++++++++++++++++---------------- > > mm/kasan/kasan.h | 12 ++++++++++-- > > mm/kasan/report.c | 16 ++++++++-------- > > 3 files changed, 34 insertions(+), 26 deletions(-) > > > > diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c > > index 18b6a2b..642d936 100644 > > --- a/mm/kasan/kasan.c > > +++ b/mm/kasan/kasan.c > > @@ -274,7 +274,7 @@ static __always_inline bool > memory_is_poisoned(unsigned long addr, size_t size) > > } > > > > static __always_inline void check_memory_region_inline(unsigned long > addr, > > - size_t size, bool write, > > + size_t size, enum > acc_type type, > > unsigned long ret_ip) > > { > > if (unlikely(size == 0)) > > @@ -282,39 +282,39 @@ static __always_inline void > check_memory_region_inline(unsigned long addr, > > > > if (unlikely((void *)addr < > > kasan_shadow_to_mem((void *)KASAN_SHADOW_START))) { > > - kasan_report(addr, size, write, ret_ip); > > + kasan_report(addr, size, type, ret_ip); > > return; > > } > > > > if (likely(!memory_is_poisoned(addr, size))) > > return; > > > > - kasan_report(addr, size, write, ret_ip); > > + kasan_report(addr, size, type, ret_ip); > > } > > > > static void check_memory_region(unsigned long addr, > > - size_t size, bool write, > > + size_t size, enum acc_type type, > > unsigned long ret_ip) > > { > > - check_memory_region_inline(addr, size, write, ret_ip); > > + check_memory_region_inline(addr, size, type, ret_ip); > > } > > > > void kasan_check_read(const void *p, unsigned int size) > > { > > - check_memory_region((unsigned long)p, size, false, _RET_IP_); > > + check_memory_region((unsigned long)p, size, READ_MODE, _RET_IP_); > > } > > EXPORT_SYMBOL(kasan_check_read); > > > > void kasan_check_write(const void *p, unsigned int size) > > { > > - check_memory_region((unsigned long)p, size, true, _RET_IP_); > > + check_memory_region((unsigned long)p, size, WRITE_MODE, > _RET_IP_); > > } > > EXPORT_SYMBOL(kasan_check_write); > > > > #undef memset > > void *memset(void *addr, int c, size_t len) > > { > > - check_memory_region((unsigned long)addr, len, true, _RET_IP_); > > + check_memory_region((unsigned long)addr, len, WRITE_MODE, > _RET_IP_); > > > > return __memset(addr, c, len); > > } > > @@ -322,8 +322,8 @@ void *memset(void *addr, int c, size_t len) > > #undef memmove > > void *memmove(void *dest, const void *src, size_t len) > > { > > - check_memory_region((unsigned long)src, len, false, _RET_IP_); > > - check_memory_region((unsigned long)dest, len, true, _RET_IP_); > > + check_memory_region((unsigned long)src, len, READ_MODE, > _RET_IP_); > > + check_memory_region((unsigned long)dest, len, WRITE_MODE, > _RET_IP_); > > > > return __memmove(dest, src, len); > > } > > @@ -331,8 +331,8 @@ void *memmove(void *dest, const void *src, size_t > len) > > #undef memcpy > > void *memcpy(void *dest, const void *src, size_t len) > > { > > - check_memory_region((unsigned long)src, len, false, _RET_IP_); > > - check_memory_region((unsigned long)dest, len, true, _RET_IP_); > > + check_memory_region((unsigned long)src, len, READ_MODE, > _RET_IP_); > > + check_memory_region((unsigned long)dest, len, WRITE_MODE, > _RET_IP_); > > > > return __memcpy(dest, src, len); > > } > > @@ -709,7 +709,7 @@ EXPORT_SYMBOL(__asan_unregister_globals); > > #define DEFINE_ASAN_LOAD_STORE(size) \ > > void __asan_load##size(unsigned long addr) \ > > { \ > > - check_memory_region_inline(addr, size, false, _RET_IP_);\ > > + check_memory_region_inline(addr, size, READ_MODE, > _RET_IP_);\ > > } \ > > EXPORT_SYMBOL(__asan_load##size); \ > > __alias(__asan_load##size) \ > > @@ -717,7 +717,7 @@ EXPORT_SYMBOL(__asan_unregister_globals); > > EXPORT_SYMBOL(__asan_load##size##_noabort); \ > > void __asan_store##size(unsigned long addr) \ > > { \ > > - check_memory_region_inline(addr, size, true, _RET_IP_); \ > > + check_memory_region_inline(addr, size, WRITE_MODE, > _RET_IP_);\ > > } \ > > EXPORT_SYMBOL(__asan_store##size); \ > > __alias(__asan_store##size) \ > > @@ -732,7 +732,7 @@ DEFINE_ASAN_LOAD_STORE(16); > > > > void __asan_loadN(unsigned long addr, size_t size) > > { > > - check_memory_region(addr, size, false, _RET_IP_); > > + check_memory_region(addr, size, READ_MODE, _RET_IP_); > > } > > EXPORT_SYMBOL(__asan_loadN); > > > > @@ -742,7 +742,7 @@ EXPORT_SYMBOL(__asan_loadN_noabort); > > > > void __asan_storeN(unsigned long addr, size_t size) > > { > > - check_memory_region(addr, size, true, _RET_IP_); > > + check_memory_region(addr, size, WRITE_MODE, _RET_IP_); > > } > > EXPORT_SYMBOL(__asan_storeN); > > > > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > > index 7f7ac51..47cb58c 100644 > > --- a/mm/kasan/kasan.h > > +++ b/mm/kasan/kasan.h > > @@ -27,11 +27,19 @@ > > #define KASAN_ABI_VERSION 1 > > #endif > > > > +/* > > + * Distinguish memory access > > + */ > > +enum acc_type { > > + READ_MODE, > > + WRITE_MODE > > +}; > > + > > struct kasan_access_info { > > const void *access_addr; > > const void *first_bad_addr; > > size_t access_size; > > - bool is_write; > > + enum acc_type access_type; > > unsigned long ip; > > }; > > > > @@ -109,7 +117,7 @@ static inline bool kasan_report_enabled(void) > > } > > > > void kasan_report(unsigned long addr, size_t size, > > - bool is_write, unsigned long ip); > > + enum acc_type type, unsigned long ip); > > > > #ifdef CONFIG_SLAB > > void quarantine_put(struct kasan_free_meta *info, struct kmem_cache > *cache); > > diff --git a/mm/kasan/report.c b/mm/kasan/report.c > > index b3c122d..e0bee22 100644 > > --- a/mm/kasan/report.c > > +++ b/mm/kasan/report.c > > @@ -96,7 +96,7 @@ static void print_error_description(struct > kasan_access_info *info) > > bug_type, (void *)info->ip, > > info->access_addr); > > pr_err("%s of size %zu by task %s/%d\n", > > - info->is_write ? "Write" : "Read", > > + info->access_type == WRITE_MODE ? "Write" : "Read", > > info->access_size, current->comm, task_pid_nr(current)); > > } > > > > @@ -267,7 +267,7 @@ static void kasan_report_error(struct > kasan_access_info *info) > > pr_err("BUG: KASAN: %s on address %p\n", > > bug_type, info->access_addr); > > pr_err("%s of size %zu by task %s/%d\n", > > - info->is_write ? "Write" : "Read", > > + info->access_type == WRITE_MODE ? "Write" : > "Read", > > info->access_size, current->comm, > > task_pid_nr(current)); > > dump_stack(); > > @@ -283,7 +283,7 @@ static void kasan_report_error(struct > kasan_access_info *info) > > } > > > > void kasan_report(unsigned long addr, size_t size, > > - bool is_write, unsigned long ip) > > + enum acc_type type, unsigned long ip) > > { > > struct kasan_access_info info; > > > > @@ -292,7 +292,7 @@ void kasan_report(unsigned long addr, size_t size, > > > > info.access_addr = (void *)addr; > > info.access_size = size; > > - info.is_write = is_write; > > + info.access_type = type; > > info.ip = ip; > > > > kasan_report_error(&info); > > @@ -302,14 +302,14 @@ void kasan_report(unsigned long addr, size_t size, > > #define DEFINE_ASAN_REPORT_LOAD(size) \ > > void __asan_report_load##size##_noabort(unsigned long addr) \ > > { \ > > - kasan_report(addr, size, false, _RET_IP_); \ > > + kasan_report(addr, size, READ_MODE, _RET_IP_); \ > > } \ > > EXPORT_SYMBOL(__asan_report_load##size##_noabort) > > > > #define DEFINE_ASAN_REPORT_STORE(size) \ > > void __asan_report_store##size##_noabort(unsigned long addr) \ > > { \ > > - kasan_report(addr, size, true, _RET_IP_); \ > > + kasan_report(addr, size, WRITE_MODE, _RET_IP_); \ > > } \ > > EXPORT_SYMBOL(__asan_report_store##size##_noabort) > > > > @@ -326,12 +326,12 @@ DEFINE_ASAN_REPORT_STORE(16); > > > > void __asan_report_load_n_noabort(unsigned long addr, size_t size) > > { > > - kasan_report(addr, size, false, _RET_IP_); > > + kasan_report(addr, size, READ_MODE, _RET_IP_); > > } > > EXPORT_SYMBOL(__asan_report_load_n_noabort); > > > > void __asan_report_store_n_noabort(unsigned long addr, size_t size) > > { > > - kasan_report(addr, size, true, _RET_IP_); > > + kasan_report(addr, size, WRITE_MODE, _RET_IP_); > > } > > EXPORT_SYMBOL(__asan_report_store_n_noabort); > > > Hello seokhoon.yoon, > > Hi Dmitry, thanks for your replies. > > Where exactly do you hit readability problems? > I don`t hit readablity problem,but kasan need to abstract this expression. I think more abstraction give us more readablity. isn't it? :) > I would say that the only problematic place is where we initialize the > value: > > kasan_report(addr, size, true, _RET_IP_); > check_memory_region(addr, size, true, _RET_IP_); > Here it is really difficult to say what true/false mean. Even if you > know that it is access type, you don't necessary remember if true means write or read. That could be solved by adding comments: > > kasan_report(addr, size, /* write = */ true, _RET_IP_); > > In all other places one sees that we are talking about "write". thanks. [-- Attachment #2: Type: text/html, Size: 15251 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] mm/kasan: use {READ,WRITE}_MODE not true,false 2016-06-05 23:08 ` SeokHoon Yoon @ 2016-06-06 14:33 ` Dmitry Vyukov 0 siblings, 0 replies; 4+ messages in thread From: Dmitry Vyukov @ 2016-06-06 14:33 UTC (permalink / raw) To: SeokHoon Yoon; +Cc: Andrey Ryabinin, kasan-dev, linux-mm, sh.yoon On Mon, Jun 6, 2016 at 1:08 AM, SeokHoon Yoon <iamyooon@gmail.com> wrote: > > 2016-06-05 21:49 GMT+09:00 Dmitry Vyukov <dvyukov@google.com>: >> >> On Sun, Jun 5, 2016 at 1:11 PM, seokhoon.yoon <iamyooon@gmail.com> wrote: >> > When Kasan tell memory access is write or not, use true or false. >> > This expression is simple and convenient. >> > >> > But I think it is possible to more readable. and so change it. >> > >> > Signed-off-by: seokhoon.yoon <iamyooon@gmail.com> >> > --- >> > mm/kasan/kasan.c | 32 ++++++++++++++++---------------- >> > mm/kasan/kasan.h | 12 ++++++++++-- >> > mm/kasan/report.c | 16 ++++++++-------- >> > 3 files changed, 34 insertions(+), 26 deletions(-) >> > >> > diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c >> > index 18b6a2b..642d936 100644 >> > --- a/mm/kasan/kasan.c >> > +++ b/mm/kasan/kasan.c >> > @@ -274,7 +274,7 @@ static __always_inline bool >> > memory_is_poisoned(unsigned long addr, size_t size) >> > } >> > >> > static __always_inline void check_memory_region_inline(unsigned long >> > addr, >> > - size_t size, bool write, >> > + size_t size, enum >> > acc_type type, >> > unsigned long ret_ip) >> > { >> > if (unlikely(size == 0)) >> > @@ -282,39 +282,39 @@ static __always_inline void >> > check_memory_region_inline(unsigned long addr, >> > >> > if (unlikely((void *)addr < >> > kasan_shadow_to_mem((void *)KASAN_SHADOW_START))) { >> > - kasan_report(addr, size, write, ret_ip); >> > + kasan_report(addr, size, type, ret_ip); >> > return; >> > } >> > >> > if (likely(!memory_is_poisoned(addr, size))) >> > return; >> > >> > - kasan_report(addr, size, write, ret_ip); >> > + kasan_report(addr, size, type, ret_ip); >> > } >> > >> > static void check_memory_region(unsigned long addr, >> > - size_t size, bool write, >> > + size_t size, enum acc_type type, >> > unsigned long ret_ip) >> > { >> > - check_memory_region_inline(addr, size, write, ret_ip); >> > + check_memory_region_inline(addr, size, type, ret_ip); >> > } >> > >> > void kasan_check_read(const void *p, unsigned int size) >> > { >> > - check_memory_region((unsigned long)p, size, false, _RET_IP_); >> > + check_memory_region((unsigned long)p, size, READ_MODE, >> > _RET_IP_); >> > } >> > EXPORT_SYMBOL(kasan_check_read); >> > >> > void kasan_check_write(const void *p, unsigned int size) >> > { >> > - check_memory_region((unsigned long)p, size, true, _RET_IP_); >> > + check_memory_region((unsigned long)p, size, WRITE_MODE, >> > _RET_IP_); >> > } >> > EXPORT_SYMBOL(kasan_check_write); >> > >> > #undef memset >> > void *memset(void *addr, int c, size_t len) >> > { >> > - check_memory_region((unsigned long)addr, len, true, _RET_IP_); >> > + check_memory_region((unsigned long)addr, len, WRITE_MODE, >> > _RET_IP_); >> > >> > return __memset(addr, c, len); >> > } >> > @@ -322,8 +322,8 @@ void *memset(void *addr, int c, size_t len) >> > #undef memmove >> > void *memmove(void *dest, const void *src, size_t len) >> > { >> > - check_memory_region((unsigned long)src, len, false, _RET_IP_); >> > - check_memory_region((unsigned long)dest, len, true, _RET_IP_); >> > + check_memory_region((unsigned long)src, len, READ_MODE, >> > _RET_IP_); >> > + check_memory_region((unsigned long)dest, len, WRITE_MODE, >> > _RET_IP_); >> > >> > return __memmove(dest, src, len); >> > } >> > @@ -331,8 +331,8 @@ void *memmove(void *dest, const void *src, size_t >> > len) >> > #undef memcpy >> > void *memcpy(void *dest, const void *src, size_t len) >> > { >> > - check_memory_region((unsigned long)src, len, false, _RET_IP_); >> > - check_memory_region((unsigned long)dest, len, true, _RET_IP_); >> > + check_memory_region((unsigned long)src, len, READ_MODE, >> > _RET_IP_); >> > + check_memory_region((unsigned long)dest, len, WRITE_MODE, >> > _RET_IP_); >> > >> > return __memcpy(dest, src, len); >> > } >> > @@ -709,7 +709,7 @@ EXPORT_SYMBOL(__asan_unregister_globals); >> > #define DEFINE_ASAN_LOAD_STORE(size) >> > \ >> > void __asan_load##size(unsigned long addr) >> > \ >> > { >> > \ >> > - check_memory_region_inline(addr, size, false, >> > _RET_IP_);\ >> > + check_memory_region_inline(addr, size, READ_MODE, >> > _RET_IP_);\ >> > } >> > \ >> > EXPORT_SYMBOL(__asan_load##size); >> > \ >> > __alias(__asan_load##size) >> > \ >> > @@ -717,7 +717,7 @@ EXPORT_SYMBOL(__asan_unregister_globals); >> > EXPORT_SYMBOL(__asan_load##size##_noabort); >> > \ >> > void __asan_store##size(unsigned long addr) >> > \ >> > { >> > \ >> > - check_memory_region_inline(addr, size, true, _RET_IP_); >> > \ >> > + check_memory_region_inline(addr, size, WRITE_MODE, >> > _RET_IP_);\ >> > } >> > \ >> > EXPORT_SYMBOL(__asan_store##size); >> > \ >> > __alias(__asan_store##size) >> > \ >> > @@ -732,7 +732,7 @@ DEFINE_ASAN_LOAD_STORE(16); >> > >> > void __asan_loadN(unsigned long addr, size_t size) >> > { >> > - check_memory_region(addr, size, false, _RET_IP_); >> > + check_memory_region(addr, size, READ_MODE, _RET_IP_); >> > } >> > EXPORT_SYMBOL(__asan_loadN); >> > >> > @@ -742,7 +742,7 @@ EXPORT_SYMBOL(__asan_loadN_noabort); >> > >> > void __asan_storeN(unsigned long addr, size_t size) >> > { >> > - check_memory_region(addr, size, true, _RET_IP_); >> > + check_memory_region(addr, size, WRITE_MODE, _RET_IP_); >> > } >> > EXPORT_SYMBOL(__asan_storeN); >> > >> > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h >> > index 7f7ac51..47cb58c 100644 >> > --- a/mm/kasan/kasan.h >> > +++ b/mm/kasan/kasan.h >> > @@ -27,11 +27,19 @@ >> > #define KASAN_ABI_VERSION 1 >> > #endif >> > >> > +/* >> > + * Distinguish memory access >> > + */ >> > +enum acc_type { >> > + READ_MODE, >> > + WRITE_MODE >> > +}; >> > + >> > struct kasan_access_info { >> > const void *access_addr; >> > const void *first_bad_addr; >> > size_t access_size; >> > - bool is_write; >> > + enum acc_type access_type; >> > unsigned long ip; >> > }; >> > >> > @@ -109,7 +117,7 @@ static inline bool kasan_report_enabled(void) >> > } >> > >> > void kasan_report(unsigned long addr, size_t size, >> > - bool is_write, unsigned long ip); >> > + enum acc_type type, unsigned long ip); >> > >> > #ifdef CONFIG_SLAB >> > void quarantine_put(struct kasan_free_meta *info, struct kmem_cache >> > *cache); >> > diff --git a/mm/kasan/report.c b/mm/kasan/report.c >> > index b3c122d..e0bee22 100644 >> > --- a/mm/kasan/report.c >> > +++ b/mm/kasan/report.c >> > @@ -96,7 +96,7 @@ static void print_error_description(struct >> > kasan_access_info *info) >> > bug_type, (void *)info->ip, >> > info->access_addr); >> > pr_err("%s of size %zu by task %s/%d\n", >> > - info->is_write ? "Write" : "Read", >> > + info->access_type == WRITE_MODE ? "Write" : "Read", >> > info->access_size, current->comm, task_pid_nr(current)); >> > } >> > >> > @@ -267,7 +267,7 @@ static void kasan_report_error(struct >> > kasan_access_info *info) >> > pr_err("BUG: KASAN: %s on address %p\n", >> > bug_type, info->access_addr); >> > pr_err("%s of size %zu by task %s/%d\n", >> > - info->is_write ? "Write" : "Read", >> > + info->access_type == WRITE_MODE ? "Write" : >> > "Read", >> > info->access_size, current->comm, >> > task_pid_nr(current)); >> > dump_stack(); >> > @@ -283,7 +283,7 @@ static void kasan_report_error(struct >> > kasan_access_info *info) >> > } >> > >> > void kasan_report(unsigned long addr, size_t size, >> > - bool is_write, unsigned long ip) >> > + enum acc_type type, unsigned long ip) >> > { >> > struct kasan_access_info info; >> > >> > @@ -292,7 +292,7 @@ void kasan_report(unsigned long addr, size_t size, >> > >> > info.access_addr = (void *)addr; >> > info.access_size = size; >> > - info.is_write = is_write; >> > + info.access_type = type; >> > info.ip = ip; >> > >> > kasan_report_error(&info); >> > @@ -302,14 +302,14 @@ void kasan_report(unsigned long addr, size_t size, >> > #define DEFINE_ASAN_REPORT_LOAD(size) \ >> > void __asan_report_load##size##_noabort(unsigned long addr) \ >> > { \ >> > - kasan_report(addr, size, false, _RET_IP_); \ >> > + kasan_report(addr, size, READ_MODE, _RET_IP_); \ >> > } \ >> > EXPORT_SYMBOL(__asan_report_load##size##_noabort) >> > >> > #define DEFINE_ASAN_REPORT_STORE(size) \ >> > void __asan_report_store##size##_noabort(unsigned long addr) \ >> > { \ >> > - kasan_report(addr, size, true, _RET_IP_); \ >> > + kasan_report(addr, size, WRITE_MODE, _RET_IP_); \ >> > } \ >> > EXPORT_SYMBOL(__asan_report_store##size##_noabort) >> > >> > @@ -326,12 +326,12 @@ DEFINE_ASAN_REPORT_STORE(16); >> > >> > void __asan_report_load_n_noabort(unsigned long addr, size_t size) >> > { >> > - kasan_report(addr, size, false, _RET_IP_); >> > + kasan_report(addr, size, READ_MODE, _RET_IP_); >> > } >> > EXPORT_SYMBOL(__asan_report_load_n_noabort); >> > >> > void __asan_report_store_n_noabort(unsigned long addr, size_t size) >> > { >> > - kasan_report(addr, size, true, _RET_IP_); >> > + kasan_report(addr, size, WRITE_MODE, _RET_IP_); >> > } >> > EXPORT_SYMBOL(__asan_report_store_n_noabort); >> >> >> Hello seokhoon.yoon, >> > Hi Dmitry, > thanks for your replies. > >> >> >> Where exactly do you hit readability problems? > > > I don`t hit readablity problem,but kasan need to abstract this expression. > I think more abstraction give us more readablity. isn't it? :) Keeping it simple also gives readability. >> I would say that the only problematic place is where we initialize the >> value: >> >> kasan_report(addr, size, true, _RET_IP_); >> check_memory_region(addr, size, true, _RET_IP_); >> >> Here it is really difficult to say what true/false mean. Even if you >> know that it is access type, you don't necessary remember if true >> >> means write or read. That could be solved by adding comments: >> >> kasan_report(addr, size, /* write = */ true, _RET_IP_); >> >> In all other places one sees that we are talking about "write". > > > thanks. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-06-06 14:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-05 11:11 [PATCH 1/1] mm/kasan: use {READ,WRITE}_MODE not true,false seokhoon.yoon
2016-06-05 12:49 ` Dmitry Vyukov
2016-06-05 23:08 ` SeokHoon Yoon
2016-06-06 14:33 ` Dmitry Vyukov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox