Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4705113iob; Sun, 8 May 2022 22:40:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAKPhypN9U1WEyZvgOktYrNFXiyWC8ne5rDkrgemdZh1zuWBM0SpnRSSRi4VYWKQr5aXoB X-Received: by 2002:a63:e20:0:b0:385:fe08:52f9 with SMTP id d32-20020a630e20000000b00385fe0852f9mr11961290pgl.99.1652074811203; Sun, 08 May 2022 22:40:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652074811; cv=none; d=google.com; s=arc-20160816; b=iyjQi4D8DCqb+IRBgKhmSU8LHsXyjy2QknFSRSZgedF7UVIMx/uCQ561I9jkPtznNn iVjW/EGSk29mMkakWaOwhCAVOIGbpAKlMwB+NZyPZc1fe+COMDeYUuG3sjkWy16VwEkW 1FKEKbQVFI6Sqy60Hydfb8c7EGPte74nJ6P1llEXBuXPwvX+K+SfYIvjNikzqXkxo3HS X136AXO2/lLxt/mSmzdnnjPMfukR78j4Wo2dwUOa/oPGzvwjHRQ/+EqpM3Pmjom/pHUY l+q7xU4nXCArWGzBUq+/HcPyY6jhqskHRD2VSYRW7wjaTBvY5h46lCG4z2CkZ4kfwFqI XiaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xBmn7X1sKMD561MY32VMh/zOVxyDoB4sLlJH4mBK1Yg=; b=c2BoIcsw2gGPO/mlBk0YeKQz5yoXFjayu+KvLlWSvzUlYA6rfAkkDzNGLPsbRirfY8 cNKFBOvm0ODHnOQprBIWKRdSd2cp5QxaDPXLpGI8BkupBnLKvNrCb0HCLZL997KUwZGh Bgwp5PIZ9DOEFt8Xdjm1YDq8pVS6aEjrIUbP4MX5L2KzPDPndUeQJIxwbCDMlktHbNFY soDCY2gX58fa+RLejA8mE8a+V5gOpsV4Eg/7rgPx/QhxG8+T1QEV4lnFYn7hlXyDG7jT pSoAJLZN5EH0VKDDWL3xQucUJvBfzuNXR1lv23QMnBz40kZKIAl/rmdZNmjbhf9XTmNy DWzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=dr3n8iEg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x1-20020a63aa41000000b003c6a5d78bb5si5541134pgo.411.2022.05.08.22.40.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 22:40:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=dr3n8iEg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5C303158F81; Sun, 8 May 2022 22:39:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238864AbiEHTGF (ORCPT + 99 others); Sun, 8 May 2022 15:06:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378051AbiEHSkd (ORCPT ); Sun, 8 May 2022 14:40:33 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD658DF40 for ; Sun, 8 May 2022 11:36:41 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id i19so23004777eja.11 for ; Sun, 08 May 2022 11:36:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xBmn7X1sKMD561MY32VMh/zOVxyDoB4sLlJH4mBK1Yg=; b=dr3n8iEg3Okpi2+98RAFGyaZsIkZq224vHkxOm2jpXBTr4bMWowz9Nq+aeGy5w2pE1 ZJ6350+ep2T6lHqgbhVu2oD65CQstrAqa+O3z6jHA46o2ZwHqJCfHDRMc+xQCXNRYAjR Y3/d9df793izCkwXzJqiiChoAuyFekvCT/hKg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xBmn7X1sKMD561MY32VMh/zOVxyDoB4sLlJH4mBK1Yg=; b=A39Q55R6TZkb9GuWI7L6u0SuqWeGp89Ck6aZib+dx/1jn56OtCTzEMPbsMrtEV5jBt mYnZnQmdrSFZdu9wWGQCNC+rAMM6y5IDzRz8kartp2Zz9GSR2OeeIWJdZ9ckZy3hDuap 53tFmb0xCOIS03kfpuQ+brnA6cFJUtlqPHhcDCTE3vRPfL7owNGYAaWSFqmbomyXSfAn aLQLiMgG9EfOeJBimInOHBbh0FP5IJCJBiwsreHwFAIG5Jw/S444E9d1kX3ixMCsZHpk UOs9hdDhqWep2XFnEd0XphwZpO1G1hLLSXjaSzMpICbJ3s6tpX3+l2ySOxfLkfAarCxB oEVQ== X-Gm-Message-State: AOAM533tBLKIqb4wWuk674xOV0LhIEZegbEXPA6mxp+wJQsrYYMZ9GKd xxgWnG7YWmd4zpc3+gU8R+D3j1s+DHedCt3y X-Received: by 2002:a17:907:1c20:b0:6f4:639e:9400 with SMTP id nc32-20020a1709071c2000b006f4639e9400mr11323490ejc.485.1652035000138; Sun, 08 May 2022 11:36:40 -0700 (PDT) Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com. [209.85.221.46]) by smtp.gmail.com with ESMTPSA id cn18-20020a0564020cb200b0042617ba639esm5099113edb.40.2022.05.08.11.36.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 May 2022 11:36:39 -0700 (PDT) Received: by mail-wr1-f46.google.com with SMTP id x18so16693665wrc.0 for ; Sun, 08 May 2022 11:36:39 -0700 (PDT) X-Received: by 2002:adf:dfc8:0:b0:20a:d256:5b5c with SMTP id q8-20020adfdfc8000000b0020ad2565b5cmr10818059wrn.97.1652034999135; Sun, 08 May 2022 11:36:39 -0700 (PDT) MIME-Version: 1.0 References: <165201148069.536527.1960632033331546251.tglx@xen13> In-Reply-To: From: Linus Torvalds Date: Sun, 8 May 2022 11:36:23 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [GIT pull] core/urgent for v5.18-rc6 To: Thomas Gleixner , Zhangfei Gao , Fenghua Yu , Jean-Philippe Brucker , Jacob Pan , Dave Hansen Cc: Linux Kernel Mailing List , "the arch/x86 maintainers" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Sun, May 8, 2022 at 11:09 AM Linus Torvalds wrote: > > Looks like it is > > ->(*sva_bind)() > -> intel_svm_bind_mm() > -> mmu_notifier_register(&svm->notifier, mm) > > and yes, the mmu notifiers annoyingly end up doing an mmgrab [..] Side note: quite independently of this mmgrab issue, I think the code in question is *very* suspect and horrendously fragile. In particular, the code ends up being called through things like this: handle = iommu_sva_bind_device(uacce->parent, current->mm, NULL); and then that Intel svm.c code does this: svm->pasid = mm->pasid; svm->mm = mm; svm->flags = flags; and saves off that mm pointer in the 'svm' structure. AND IT NEVER TAKES ANY REFERENCE TO IT AT ALL! It then does mm = svm->mm; later at some unspecified time, and the 'mm' might long since have died. In other words, the code works almost by accident - the only user of the 'mm' pointer seems to be that mmu_notifier_register() thing, so it basically treats the 'struct mm_struct' as something as a random cookie. And yes, the mmu notifiers do then take that mmgrab reference to the mm, so it all works. But it sure looks horrendously ugly. Saving off a 'struct mm_struct' pointer with having basically an accidental reference to it is WRONG. In fact, it will save off that pointer whether it then actually does the mmu_notifier thing on it, because the code actually does [...] svm->mm = mm; svm->flags = flags; INIT_LIST_HEAD_RCU(&svm->devs); if (!(flags & SVM_FLAG_SUPERVISOR_MODE)) { svm->notifier.ops = &intel_mmuops; ret = mmu_notifier_register(&svm->notifier, mm); [...] so that mmu_notifier_register() call is conditional. On the freeing path, it then uses that "svm->notifier.ops" pointer as a "did we register this thing or not" flag, so again - it all technically *works*, but this is all horrendously ugly and wrong on so many levels, keeping pointers around with very dubious reference counting indeed. Linus