Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp426759rdb; Thu, 5 Oct 2023 09:46:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJEGj0yM44zp1PUhtHwvlXNqSe48kUqztDXox9YpJBnnsa2Q71/2+2psbs8cqCB6n+/2us X-Received: by 2002:a05:6358:42a6:b0:148:1a09:2469 with SMTP id s38-20020a05635842a600b001481a092469mr3620835rwc.25.1696524374700; Thu, 05 Oct 2023 09:46:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696524374; cv=none; d=google.com; s=arc-20160816; b=j0/egqkRLq6UMgrMCzfQwK3ZQEel6ld6r5IKnB+Ygp8GE0vFLg0gNc/NAKrUX4ALZx UFzyq+YBqnZ56pUGEWf9VaEyzfcLJJiN2gJH0ZtqG9P/XC2f93VJ9vX6LW6b5m0CAxfK VSXqUFg84FdoogTjE77stI18eN0XYlfQYe9U4zGC9kE2GWvaNQHuJwgGSYDrHwFb7Z7o 03VUlblkw+jFCYSlMQxeF329KErwW1t0Xzd95gcFlR+m8UPvc0zMEw/9GVOghhVFRJWw HH00hZETqgF/HdYydc6qcBvUJojkyZeF8WKXu2ENdOp7gwpXB+olzDutFuS0PNS1/+ja 94Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=kcIHJd8zrYki+Wg0RoULYhP1Y/OyxEQ+26ogj6n5WEc=; fh=hGEgc+H2lqjQZHittc2ha0RF7HaeXzWWvqMTXCnUr/U=; b=mZFGN5tXW++ayUwfqA712VoGj4rG/rGomc0uav+eImnwRkt6cksH1H+EAWbu69fqIK 0mtVqtGuCnjzJIBSdevEoK+u4pri4Uk22z+qtECjC4koDT7nKv+hMs2tdnb7rUCed+13 68oaq7ntmkC+LXKftX7GA6CJk9egPqgZz/RLGzFPOz+fOaTRtoCacKhyhNZJnRRT2rOK BIQ+w8QphiS3znY5Zk2M2vmhJLiWCry1rIWNpoP9Em7zD4ia4LhQ97ZxHpqYKnu2mGQ4 lmD1+hhdzzgwisXdt0hNEpMIkvWhpYAxrdL0w6hK6SHFiOZcvbr3zesL8Ytj1hMCT6BI 8dPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gM0+0oOS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id fv18-20020a17090b0e9200b00276ea6d9ac3si3964350pjb.182.2023.10.05.09.46.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:46:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gM0+0oOS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 4015B82685DC; Thu, 5 Oct 2023 09:45:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231182AbjJEQnu (ORCPT + 99 others); Thu, 5 Oct 2023 12:43:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232107AbjJEQmL (ORCPT ); Thu, 5 Oct 2023 12:42:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FE5719A2 for ; Thu, 5 Oct 2023 09:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696523127; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kcIHJd8zrYki+Wg0RoULYhP1Y/OyxEQ+26ogj6n5WEc=; b=gM0+0oOS9pwkJW7zC0CkzWMTvzCm6pHZK4/JSxiFUyzkV8qhAB0zSPMcikI/qerG03il/j YnupQpcdz/V3QqxyddNMohVZiwmM2j73YWH/Ksn0uFyyyD4WitVDxCrrwjnIxOWZi1gvsh Sn6wjUKDe8XY8JZ7rcO4XYZiisRJoo8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-470-R_aqFmEYMeisHvtuHQG8fQ-1; Thu, 05 Oct 2023 12:25:20 -0400 X-MC-Unique: R_aqFmEYMeisHvtuHQG8fQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F1AA85A5A8; Thu, 5 Oct 2023 16:25:19 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.69]) by smtp.corp.redhat.com (Postfix) with SMTP id 6A7E02156711; Thu, 5 Oct 2023 16:25:16 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 5 Oct 2023 18:24:21 +0200 (CEST) Date: Thu, 5 Oct 2023 18:24:17 +0200 From: Oleg Nesterov To: Li Nan Cc: Khazhy Kumykov , 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 Message-ID: <20231005162417.GA32420@redhat.com> References: <20230928015858.1809934-1-linan666@huaweicloud.com> <4ace01e8-6815-29d0-70ce-4632818ca701@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4ace01e8-6815-29d0-70ce-4632818ca701@huaweicloud.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 05 Oct 2023 09:45:42 -0700 (PDT) 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.