linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Li Nan <linan666@huaweicloud.com>
Cc: Khazhy Kumykov <khazhy@chromium.org>,
	tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk,
	yukuai3@huawei.com, cgroups@vger.kernel.org,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com
Subject: Re: [PATCH] blk-throttle: Calculate allowed value only when the throttle is enabled
Date: Thu, 5 Oct 2023 18:24:17 +0200	[thread overview]
Message-ID: <20231005162417.GA32420@redhat.com> (raw)
In-Reply-To: <4ace01e8-6815-29d0-70ce-4632818ca701@huaweicloud.com>

Hi Li,

On 10/05, Li Nan wrote:
>
> >I don't think this change is sufficient to prevent kernel crash, as a
> >"clever" user could still set the bps_limit to U64_MAX - 1 (or another
> >large value), which probably would still result in the same crash. The
> >comment in mul_u64_u64_div_u64 suggests there's something we can do to
> >better handle the overflow case, but I'm not sure what it's referring
> >to. ("Will generate an #DE when the result doesn't fit u64, could fix
> >with an __ex_table[] entry when it becomes an issue.") Otherwise, we
>
> When (a * mul) overflows, a divide 0 error occurs in
> mul_u64_u64_div_u64(). Commit 3dc167ba5729 ("sched/cputime: Improve
> cputime_adjust()") changed func and said: "Will generate an #DE when the
> result doesn't fit u64, could fix with an __ex_table[] entry when it
> becomes an issue." But we are unsure of how to fix it. Could you please
> explain how to fix this issue.

Not sure I understand the question...

OK, we can change mul_u64_u64_div_u64() to trap the exception, say,

	static inline u64 mul_u64_u64_div_u64(u64 a, u64 mul, u64 div)
	{
		u64 q;

		asm ("mulq %2; 1: divq %3; 2:\n"
		     _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_DEFAULT|EX_FLAG_CLEAR_AX)
					: "=a" (q)
					: "a" (a), "rm" (mul), "rm" (div)
					: "rdx");

		return q;
	}

should (iiuc) return 0 if the result doesn't fit u64 or div == 0.

But even if we forget that this is x86-specific, how can this help?
What should calculate_bytes_allowed() do/return in this case?

> >probably need to remove the mul_u64_u64_div_u64 and check for
> >overflow/potential overflow ourselves?

probably yes...

Oleg.


  parent reply	other threads:[~2023-10-05 16:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-28  1:58 [PATCH] blk-throttle: Calculate allowed value only when the throttle is enabled linan666
2023-10-04 19:31 ` Tejun Heo
2023-10-04 20:30   ` Khazhy Kumykov
2023-10-04 20:44 ` Khazhy Kumykov
     [not found]   ` <4ace01e8-6815-29d0-70ce-4632818ca701@huaweicloud.com>
2023-10-05 16:24     ` Oleg Nesterov [this message]
2023-10-07  1:23       ` Yu Kuai
2023-10-07 15:16         ` Oleg Nesterov
2023-10-08  1:26           ` Yu Kuai
2023-10-08 11:36             ` Oleg Nesterov
2023-10-13 21:51               ` Khazhy Kumykov
2023-10-16  1:46                 ` Yu Kuai
2023-10-16 20:06                   ` Khazhy Kumykov
2023-10-16 21:48                     ` Khazhy Kumykov
2023-10-17  2:38                     ` Yu Kuai
2023-10-05 17:04     ` Oleg Nesterov
2023-10-05 17:15       ` Khazhy Kumykov

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=20231005162417.GA32420@redhat.com \
    --to=oleg@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=cgroups@vger.kernel.org \
    --cc=houtao1@huawei.com \
    --cc=josef@toxicpanda.com \
    --cc=khazhy@chromium.org \
    --cc=linan666@huaweicloud.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).