Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp3862672ima; Mon, 4 Feb 2019 06:28:46 -0800 (PST) X-Google-Smtp-Source: ALg8bN7BnZEpRSnnAb/5p8AReCPGzlYlfjCu51PIOf42iV2fb5feOtFZDANpjo/y6AI8Za8T3r+2 X-Received: by 2002:a63:1c61:: with SMTP id c33mr45292262pgm.354.1549290526404; Mon, 04 Feb 2019 06:28:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549290526; cv=none; d=google.com; s=arc-20160816; b=Tndlm86adWAK0PYPeWCmmjjDY+eH4DRa7bPxCi2SoO69isB7C6MbjWxk46Z2EP48Co ghcFmeL9l+6ao95ZfXYYzKU2ylfjGGmVfUL45m8wogGuV0YrcsrUjb37CRCqPwKgGe0o 7NNg4DzEzNunxnOOFHFVqdIzy1pup94c55VJ5UrfCR6HYlUSbgv0blT1wV9Dh5N8qQy9 cAay1Eu8KBzCQUsZ9DovKm6otm1MV8sRoOVnMPipwSibrKPaE6+4M76WgzCfN3qQ9JRr qyg6tx31HV1zIO6fdcnilcS99JVpgZ3nz7pEYyPx0Y0E73nnXsR/JZ1dqsm7gZLxLypL zl3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=viDdDuJz1vRxw+tAQZx6SCEgP18OxyQCZUobRUe2nP4=; b=miXPNuuOUUObBumGLPPFot3qiHVRGXl2g8Gq2KVyHvfjAwi/BreRSDy16tKi4rpy+I BvGyTYygXQvRzfNSnzXJfjwDqq2rRMKcOqgYNNi0y5b45PnGjvx14GrwD8q9pe0sQBBU JfVIj+PYEd3eE1ipyfEUFa/UxHdI6qEe/rl4Lfs9hODOikKaR+wPWH67AgnBEzNpMQN8 YcAVQZdKK+cWOOEdjPyEegztv1t0308296J5ME9P7ijjgreBIaD7TRNBq6Vbjdvt0ryP ICEu2fWoQ4h3GRuusCS0cw9Gt1icyqxmLb8doig+onmp/h9pgYber0nBUnFyg8iS1FZS e5Cw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q4si175851pls.101.2019.02.04.06.28.30; Mon, 04 Feb 2019 06:28:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730344AbfBDN1Y (ORCPT + 99 others); Mon, 4 Feb 2019 08:27:24 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:55544 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727062AbfBDN1Y (ORCPT ); Mon, 4 Feb 2019 08:27:24 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9B46815AB; Mon, 4 Feb 2019 05:27:23 -0800 (PST) Received: from [10.1.197.45] (e112298-lin.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A943B3F557; Mon, 4 Feb 2019 05:27:21 -0800 (PST) Subject: Re: [PATCH v3 3/4] uaccess: Check no rescheduling function is called in unsafe region To: Valentin Schneider , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: mingo@redhat.com, peterz@infradead.org, catalin.marinas@arm.com, will.deacon@arm.com, james.morse@arm.com, hpa@zytor.com References: <1547560709-56207-1-git-send-email-julien.thierry@arm.com> <1547560709-56207-4-git-send-email-julien.thierry@arm.com> <9ba3c7a7-80a8-da29-ffb7-3841ea8548b5@arm.com> From: Julien Thierry Message-ID: Date: Mon, 4 Feb 2019 13:27:17 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <9ba3c7a7-80a8-da29-ffb7-3841ea8548b5@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30/01/2019 16:58, Valentin Schneider wrote: > On 15/01/2019 13:58, Julien Thierry wrote: > [...]> @@ -6151,6 +6159,20 @@ void ___might_sleep(const char *file, int line, int preempt_offset) >> EXPORT_SYMBOL(___might_sleep); >> #endif >> >> +#ifdef CONFIG_DEBUG_UACCESS_SLEEP >> +void __might_resched(const char *file, int line) >> +{ >> + if (!unsafe_user_region_active()) >> + return; >> + >> + printk(KERN_ERR >> + "BUG: rescheduling function called from user access context at %s:%d\n", >> + file, line); >> + dump_stack(); > > Since I've been staring intensely at ___might_sleep() lately, I was thinking > we could "copy" it a bit more closely (sorry for going back on what I said > earlier). > > Coming back to the double warnings (__might_resched() + schedule_debug()), > it might be better to drop the schedule_debug() warning and just have the > one in __might_resched() - if something goes wrong, there'll already be a > "BUG" in the log. > My only worry with that approach is that if someone has a function that does resched but does not include the annotation __might_resched() we'd miss the fact that something went wrong. But that might be a lot of "if"s since that assumes that something does go wrong. Could I have a maintainers opinion on this to know if I respin it? >> +} >> +EXPORT_SYMBOL(__might_resched); >> +#endif >> + >> #ifdef CONFIG_MAGIC_SYSRQ >> void normalize_rt_tasks(void) >> { >> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug >> index d4df5b2..d030e31 100644 >> --- a/lib/Kconfig.debug >> +++ b/lib/Kconfig.debug >> @@ -2069,6 +2069,14 @@ config IO_STRICT_DEVMEM >> >> If in doubt, say Y. >> >> +config DEBUG_UACCESS_SLEEP >> + bool "Check sleep inside a user access region" >> + depends on DEBUG_KERNEL >> + help >> + If you say Y here, various routines which may sleep will become very >> + noisy if they are called inside a user access region (i.e. between >> + a user_access_begin() and a user_access_end()) > > If it does get noisy, we should go for some ratelimiting - it's probably > good practice even if it is not noisy actually. > > ___might_sleep() has this: > > if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) > return; > prev_jiffy = jiffies; > I guess the noisiness could depend on the arch specific handling of user accesses. So yes I guess it might be a good idea to add this. Thanks, -- Julien Thierry