From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26C31C43603 for ; Fri, 13 Dec 2019 21:21:48 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7E20120663 for ; Fri, 13 Dec 2019 21:21:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7E20120663 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47ZNs524KbzDrCB for ; Sat, 14 Dec 2019 08:21:45 +1100 (AEDT) Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47ZNph06HmzDqvt for ; Sat, 14 Dec 2019 08:19:40 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Received: by ozlabs.org (Postfix, from userid 1034) id 47ZNpf6p2kz9sPJ; Sat, 14 Dec 2019 08:19:38 +1100 (AEDT) X-powerpc-patch-notification: thanks X-powerpc-patch-commit: a58d37bce0d21cf7fbd589384c619e465ef2f927 In-Reply-To: <20190624144148.32022-1-fbarrat@linux.ibm.com> To: Frederic Barrat , linuxppc-dev@lists.ozlabs.org, andrew.donnellan@au1.ibm.com, clombard@linux.ibm.com, groug@kaod.org, alastair@au1.ibm.com From: Michael Ellerman Subject: Re: [PATCH] ocxl: Fix concurrent AFU open and device removal Message-Id: <47ZNpf6p2kz9sPJ@ozlabs.org> Date: Sat, 14 Dec 2019 08:19:38 +1100 (AEDT) X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Mon, 2019-06-24 at 14:41:48 UTC, Frederic Barrat wrote: > If an ocxl device is unbound through sysfs at the same time its AFU is > being opened by a user process, the open code may dereference freed > stuctures, which can lead to kernel oops messages. You'd have to hit a > tiny time window, but it's possible. It's fairly easy to test by > making the time window bigger artificially. > > Fix it with a combination of 2 changes: > - when an AFU device is found in the IDR by looking for the device > minor number, we should hold a reference on the device until after the > context is allocated. A reference on the AFU structure is kept when > the context is allocated, so we can release the reference on the > device after the context allocation. > - with the fix above, there's still another even tinier window, > between the time the AFU device is found in the IDR and the reference > on the device is taken. We can fix this one by removing the IDR entry > earlier, when the device setup is removed, instead of waiting for the > 'release' device callback. With proper locking around the IDR. > > Fixes: 75ca758adbaf ("ocxl: Create a clear delineation between ocxl backend & frontend") > Signed-off-by: Frederic Barrat Applied to powerpc fixes, thanks. https://git.kernel.org/powerpc/c/a58d37bce0d21cf7fbd589384c619e465ef2f927 cheers