All of lore.kernel.org
 help / color / mirror / Atom feed
From: hw.likun@huawei.com (Li Kun)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] arm64: kernel: implement fast refcount checking
Date: Wed, 26 Jul 2017 12:11:52 +0800	[thread overview]
Message-ID: <0816933d-7e58-0773-1441-891823983ff9@huawei.com> (raw)
In-Reply-To: <20170725181536.21092-1-ard.biesheuvel@linaro.org>

Hi Ard?


on 2017/7/26 2:15, Ard Biesheuvel wrote:
> +#define REFCOUNT_OP(op, asm_op, cond, l, clobber...)			\
> +__LL_SC_INLINE int							\
> +__LL_SC_PREFIX(__refcount_##op(int i, atomic_t *r))			\
> +{									\
> +	unsigned long tmp;						\
> +	int result;							\
> +									\
> +	asm volatile("// refcount_" #op "\n"				\
> +"	prfm		pstl1strm, %2\n"				\
> +"1:	ldxr		%w0, %2\n"					\
> +"	" #asm_op "	%w0, %w0, %w[i]\n"				\
> +"	st" #l "xr	%w1, %w0, %2\n"					\
> +"	cbnz		%w1, 1b\n"					\
> +	REFCOUNT_CHECK(cond)						\
> +	: "=&r" (result), "=&r" (tmp), "+Q" (r->counter)		\
> +	: REFCOUNT_INPUTS(r) [i] "Ir" (i)				\
> +	clobber);							\
> +									\
> +	return result;							\
> +}									\
> +__LL_SC_EXPORT(__refcount_##op);
> +
> +REFCOUNT_OP(add_lt, adds, mi,  , REFCOUNT_CLOBBERS);
> +REFCOUNT_OP(sub_lt_neg, adds, mi, l, REFCOUNT_CLOBBERS);
> +REFCOUNT_OP(sub_le_neg, adds, ls, l, REFCOUNT_CLOBBERS);
> +REFCOUNT_OP(sub_lt, subs, mi, l, REFCOUNT_CLOBBERS);
> +REFCOUNT_OP(sub_le, subs, ls, l, REFCOUNT_CLOBBERS);
> +
I'm not quite sure if we use b.lt to judge whether the result of adds is 
less than zero is correct or not.
The b.lt means N!=V, take an extreme example, if we operate like below, 
the b.lt will also be true.

refcount_set(&ref_c,0x80000000);
refcount_dec_and_test(&ref_c);

maybe we should use PL/NE/MI/EQ to judge the LT_ZERO or LE_ZERO condition ?

-- 
Best Regards
Li Kun

WARNING: multiple messages have this Message-ID (diff)
From: Li Kun <hw.likun@huawei.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: linux-arm-kernel@lists.infradead.org,
	kernel-hardening@lists.openwall.com, will.deacon@arm.com,
	keescook@chromium.org, mark.rutland@arm.com,
	labbott@fedoraproject.org
Subject: [kernel-hardening] Re: [PATCH v2] arm64: kernel: implement fast refcount checking
Date: Wed, 26 Jul 2017 12:11:52 +0800	[thread overview]
Message-ID: <0816933d-7e58-0773-1441-891823983ff9@huawei.com> (raw)
In-Reply-To: <20170725181536.21092-1-ard.biesheuvel@linaro.org>

Hi Ard,


on 2017/7/26 2:15, Ard Biesheuvel wrote:
> +#define REFCOUNT_OP(op, asm_op, cond, l, clobber...)			\
> +__LL_SC_INLINE int							\
> +__LL_SC_PREFIX(__refcount_##op(int i, atomic_t *r))			\
> +{									\
> +	unsigned long tmp;						\
> +	int result;							\
> +									\
> +	asm volatile("// refcount_" #op "\n"				\
> +"	prfm		pstl1strm, %2\n"				\
> +"1:	ldxr		%w0, %2\n"					\
> +"	" #asm_op "	%w0, %w0, %w[i]\n"				\
> +"	st" #l "xr	%w1, %w0, %2\n"					\
> +"	cbnz		%w1, 1b\n"					\
> +	REFCOUNT_CHECK(cond)						\
> +	: "=&r" (result), "=&r" (tmp), "+Q" (r->counter)		\
> +	: REFCOUNT_INPUTS(r) [i] "Ir" (i)				\
> +	clobber);							\
> +									\
> +	return result;							\
> +}									\
> +__LL_SC_EXPORT(__refcount_##op);
> +
> +REFCOUNT_OP(add_lt, adds, mi,  , REFCOUNT_CLOBBERS);
> +REFCOUNT_OP(sub_lt_neg, adds, mi, l, REFCOUNT_CLOBBERS);
> +REFCOUNT_OP(sub_le_neg, adds, ls, l, REFCOUNT_CLOBBERS);
> +REFCOUNT_OP(sub_lt, subs, mi, l, REFCOUNT_CLOBBERS);
> +REFCOUNT_OP(sub_le, subs, ls, l, REFCOUNT_CLOBBERS);
> +
I'm not quite sure if we use b.lt to judge whether the result of adds is 
less than zero is correct or not.
The b.lt means N!=V, take an extreme example, if we operate like below, 
the b.lt will also be true.

refcount_set(&ref_c,0x80000000);
refcount_dec_and_test(&ref_c);

maybe we should use PL/NE/MI/EQ to judge the LT_ZERO or LE_ZERO condition ?

-- 
Best Regards
Li Kun

  parent reply	other threads:[~2017-07-26  4:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-25 18:15 [PATCH v2] arm64: kernel: implement fast refcount checking Ard Biesheuvel
2017-07-25 18:15 ` [kernel-hardening] " Ard Biesheuvel
2017-07-26  3:32 ` Li Kun
2017-07-26  3:32   ` [kernel-hardening] " Li Kun
2017-07-26  4:11 ` Li Kun [this message]
2017-07-26  4:11   ` Li Kun
2017-07-26  8:40   ` Ard Biesheuvel
2017-07-26  8:40     ` [kernel-hardening] " Ard Biesheuvel
2017-07-26  9:21     ` Li Kun
2017-07-26  9:21       ` [kernel-hardening] " Li Kun
2017-07-26 13:25       ` Ard Biesheuvel
2017-07-26 13:25         ` [kernel-hardening] " Ard Biesheuvel
2017-07-27  2:11         ` Li Kun
2017-07-27  2:11           ` [kernel-hardening] " Li Kun
2017-07-27  4:16           ` Kees Cook
2017-07-27  4:16             ` [kernel-hardening] " Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0816933d-7e58-0773-1441-891823983ff9@huawei.com \
    --to=hw.likun@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.