Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp810844rwb; Wed, 9 Nov 2022 08:54:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf66MZrkWYwUjUh0CDCpVFi8Fla7AWseSeo2voatYF579ucaUPsYIvrqr76oZ3gZowP41eUr X-Received: by 2002:a50:8742:0:b0:466:45c8:1e35 with SMTP id 2-20020a508742000000b0046645c81e35mr18481608edv.395.1668012868881; Wed, 09 Nov 2022 08:54:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668012868; cv=none; d=google.com; s=arc-20160816; b=pT1S8cj2FIg8ahblk0EoXHJCYk526of/SwrHIwNj3EzIAdN/hvcug8gDWhW9nd+xYP MSzQUWti52zdCEPVUc23rwQkqf1L9Tmmy0aCDpMqn3/2e5BsOAx86LW0FpzGuWPTjXA7 6g6BnjDp8X+UVMoVbADGiwyqgw6GYrphEMiy5WK/3FkpGsxnswF4amhM0JW9EjMydOmG L8cazk+AqRrq70ol8APFiEOPnl0tOvGWw1GsNgrrlEJrxhz7QwPExJiB3vin2e5/oMeS Ped3TkzaQA5ifZRFUTJQ2N+aer7gc1O3FJiMZ5xP1uoWOm7rr+2Dy/X/0TWIcucnz/nT U3wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=dS+4jgWIp3j9dZW4rFcYGh+sxLvaYK0P20ezcjFZXV4=; b=mvLLg1UGIC+dLKPGA7AgjEkfjhGnQfieuyGyy9f9uzP96nsa/7qRlt26RgNayNKo+G mFavFL77kltAE7hqnEx6mGZp5aB+Qr6vT8RiyP5Yv0bqEnGic2bZDT6ErGAaUlO7kxeT HndRI42iBPzTk9vSjULML0LenBcX+fTkklZJI3C3IL4JOnxR0yG91ZDDISzKpAmLmDsH NPtrtsqBJR8w/2RbW22rQofzHp46PnsxZLxExmIRpX0jijx8Le2WMQBpCVAXp01GkUai HCsYkEVeKVu3Q6VUtP7lQwIjfuFoNNM3DTPG1TuuGILm47MZ+E0QdRyt0oiNqLFV/uQV qseA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QSJ6LNle; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a17090658cb00b0079a9eed8c1bsi18259579ejs.894.2022.11.09.08.54.06; Wed, 09 Nov 2022 08:54:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QSJ6LNle; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231605AbiKIQZx (ORCPT + 92 others); Wed, 9 Nov 2022 11:25:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231384AbiKIQZu (ORCPT ); Wed, 9 Nov 2022 11:25:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2946119286; Wed, 9 Nov 2022 08:25:50 -0800 (PST) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668011148; 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=dS+4jgWIp3j9dZW4rFcYGh+sxLvaYK0P20ezcjFZXV4=; b=QSJ6LNleWHA1RHSFfXDxaPCmn+jVt13MdBC439LXEnVNK/hFvPdwB5B398jBp60AT0pIQS wkqvdpn5kNXVCgwTko1XfQm3JRQBr3TviBBKhxWn75PHzday7t36VquvGBZxeXzW4Mq903 GOSrp4WESbB4JPlcJS/Wpy8DjKYKhUT6t/c1h4omwmQRuTXbyzKc/XXcibunUtKGkKFP79 YJuAAUklyZ9CwQahkEIezqyCJr5OwWQkK/nbuN5T+oPHHAX+OkBoTY8Q+NZl46O8jaiajH wEZFLs7VED6bVxf/7x4LDLExXVvd1qzAcqcrXCststE9EtbGwDQ8l63yV4xGDw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668011148; 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=dS+4jgWIp3j9dZW4rFcYGh+sxLvaYK0P20ezcjFZXV4=; b=lwdaORWqUif3kCYJceQQDzwyZjs2HDufqdzeXFV9iRm3q2ov1baXwSOqmazm7c/nIxYJ9M cbqO7rZS1r9gftBA== To: Mel Gorman Cc: "Chang S. Bae" , Borislav Petkov , Mike Galbraith , LKML , Linux-RT Subject: Re: [RFC PATCH] x86: Drop fpregs lock before inheriting FPU permissions during clone In-Reply-To: <20221109113044.7ncdw6263o3msycl@techsingularity.net> References: <20221109113044.7ncdw6263o3msycl@techsingularity.net> Date: Wed, 09 Nov 2022 17:25:47 +0100 Message-ID: <87o7tg8584.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 09 2022 at 11:30, Mel Gorman wrote: > BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:46 ... > The splat comes from fpu_inherit_perms() being called under fpregs_lock(), > and us reaching the spin_lock_irq() therein due to fpu_state_size_dynamic() > returning true despite static key __fpu_state_size_dynamic having never > been enabled. > > Mike's assessment looks correct. fpregs_lock on PREEMPT_RT disables > preemption only so the spin_lock_irq() in fpu_inherit_perms is unsafe > and converting siglock to raw spinlock would be an unwelcome change. > This problem exists since commit 9e798e9aa14c ("x86/fpu: Prepare fpu_clone() > for dynamically enabled features"). While the bug triggering is probably a > mistake for the affected machine and due to a bug that is not in mainline, > spin_lock_irq within a preempt_disable section on PREEMPT_RT is problematic. > > In this specific context, it may not be necessary to hold fpregs_lock at > all. The lock is necessary when editing the FPU registers or a tasks fpstate > but in this case, the only write of any FP state in fpu_inherit_perms is > for the new child which is not running yet so it cannot context switch or > be borrowed by a kernel thread yet. Hence, fpregs_lock is not protecting > anything in the new child until clone() completes. The siglock still needs > to be acquired by fpu_inherit_perms as the read of the parents permissions > has to be serialised. That's correct and siglock is the real protection for the permissions. > This is not tested as I did not access to a machine with Intel's > eXtended Feature Disable (XFD) feature that enables the relevant path > in fpu_inherit_perms and the bug is against a non-mainline kernel. It's still entirely correct on mainline as there is no requirement to hold fpregs_lock in this case > Reported-by: Mike Galbraith > Signed-off-by: Mel Gorman Reviewed-by: Thomas Gleixner