Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2498419rwo; Thu, 3 Aug 2023 10:11:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlF2GYnqKF9PILW1Xz1kBtDlWny4Vki5SPXxbESYsSDkyMFZR9q+wq2l7jn39xkWs+H4LFHe X-Received: by 2002:a05:6a00:b4e:b0:67f:48a2:5d9f with SMTP id p14-20020a056a000b4e00b0067f48a25d9fmr25009187pfo.11.1691082678227; Thu, 03 Aug 2023 10:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691082678; cv=none; d=google.com; s=arc-20160816; b=p4otoZiuH6n/Z6jlqkNVYaTPCJhux2eLYi+FxNbuHFVaqZnFui/GrRDdvjWA5CBfWa kBpdxqDwAQ6gNd5iOcnI8NOsvRxHqeohVQLo13t9HscJwUf0bBXixmqA7hfAiy8ZeNwC UQMru3cWOBapr2eUAiX6HC62Bx8hsTsmxKQbih0K/+D2ak/kEgLqWyCSyKhk14ATXyvj 0bwp5Ect2tZSWpFhV80zWGBsRzh3wndXLiaXve85GU1lGeEB6W9+dJ5D1Ml4WD1co8Ft fLtfmyIgbJLewiqOK/utFE41P+jpqqD5cN2nwVxVJuTLcPQLSJIoNaUMCbF7u2J1J58/ BAxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=alsHbM1v/nfjzdcfXP8ctyTsH1REwc9fdwebIn1r7Ck=; fh=B1QDrSqQ7DH/A+iMQinplOFinWDYFpt4G4oISTnZv80=; b=QVzpwTNjy2/ajE67v0kVPXmRKIOegz8brHf68TNw9to1DqSVJR0Si42nwoLMYynGUm zWvOAc7SvsR8N9uEk5KxrslKAX48lyno/LUy1OfJGptABDLTbcYLXO2ZnGCibFNs9NLX ZbtXZD76vMrzHDym3uxr+4wj4N7/U/XxDHby9L6C81wGwUr5NjnxJGN+gmctZpnOCO30 CdrbHi3bVU0eaeAarzFyMS/ixM9VBvnh38NasLaKx0zQ1im0xoz14fS2Kz9KnRbPmwi/ iruhvCMgLWeundMfeGdEt8O6K/VnYM/Gu1ZOXo7cbaE6zCD0zZwcOw1+DX9FFsuNVXVQ SeOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PyrY7hV4; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d9-20020a056a0024c900b006875f6c46b9si216653pfv.141.2023.08.03.10.11.05; Thu, 03 Aug 2023 10:11:18 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=PyrY7hV4; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235526AbjHCPNF (ORCPT + 99 others); Thu, 3 Aug 2023 11:13:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbjHCPNE (ORCPT ); Thu, 3 Aug 2023 11:13:04 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6AA5E72 for ; Thu, 3 Aug 2023 08:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691075539; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=alsHbM1v/nfjzdcfXP8ctyTsH1REwc9fdwebIn1r7Ck=; b=PyrY7hV4wAe+1vE2JnYXWykKCfDtKsnWMCnvTp7tYXjLnpXA72k8z3hKc+36rLtozSRyx7 jyGRi13mCmTicOGFom/5pA7IUOUnjWE9uPpRnJxwaQUr7lrNhyjSc5W9EMfyf42Tkopkki RcY+fqUDe0ff4SUD86zzXsbiQ1S1siM= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-427-C_RqZDzRP6mratwtsWJl1A-1; Thu, 03 Aug 2023 11:12:16 -0400 X-MC-Unique: C_RqZDzRP6mratwtsWJl1A-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5230741478cso749420a12.0 for ; Thu, 03 Aug 2023 08:12:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691075534; x=1691680334; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=alsHbM1v/nfjzdcfXP8ctyTsH1REwc9fdwebIn1r7Ck=; b=bb7OWQ7eUph/SSExXhYo4oEMdsJxNH7AuJTJl+eiomRqCX2m63YEELtBsZfdk++69m u5ZYOWWIQ6ndxVfBP2WG8kyuMwJbKwdzC0E2TJRQn2qOPRTGVj27zTSNgemyy5T2Jf3v vVzAYw0WPgo1a8MdcSh3xmFpxDWWR8pBo1yTMTTca5k1SaB86siLDVzEId2HjJUCE8iO Vp4fceMHNLpP+Lo9RxsMXhMCq4bV2TnUqpMxA7i/IpozLe+GwuDKN4zDrS05vt7S3jFg iAet66sbE2Gry6GI4xV37hKoIiS48AoqxPmJhrUNBjou/ji1ZETHks/t2CmTV4BwmlKt 3s/A== X-Gm-Message-State: ABy/qLY+FRvFUqTMWG0RM3rk4iBJicQ+NnFgL+e7Y1ySs5KRuV4ydYJr vsKTaMBPY1NwCue+HMxWD+lUY5mRnv67Pzq5z+MzVPW1n2nxF8ky7idTNbj/D3q7hebLdiNpdIf DhfYgOaCnVwvg/asjsMfqt9MAE6h8kvEX X-Received: by 2002:aa7:d382:0:b0:522:56d8:49c0 with SMTP id x2-20020aa7d382000000b0052256d849c0mr8093417edq.37.1691075534425; Thu, 03 Aug 2023 08:12:14 -0700 (PDT) X-Received: by 2002:aa7:d382:0:b0:522:56d8:49c0 with SMTP id x2-20020aa7d382000000b0052256d849c0mr8093399edq.37.1691075534052; Thu, 03 Aug 2023 08:12:14 -0700 (PDT) Received: from redhat.com ([2.52.12.104]) by smtp.gmail.com with ESMTPSA id bf19-20020a0564021a5300b0051ded17b30bsm10280982edb.40.2023.08.03.08.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 08:12:13 -0700 (PDT) Date: Thu, 3 Aug 2023 11:12:10 -0400 From: "Michael S. Tsirkin" To: Dragos Tatulea Cc: "jasowang@redhat.com" , "xuanzhuo@linux.alibaba.com" , "virtualization@lists.linux-foundation.org" , "eperezma@redhat.com" , "linux-kernel@vger.kernel.org" , "bhe@redhat.com" , "stable@vger.kernel.org" , Saeed Mahameed , "ruyang@redhat.com" Subject: Re: [PATCH] vdpa/mlx5: Fix crash on shutdown for when no ndev exists Message-ID: <20230803111154-mutt-send-email-mst@kernel.org> References: <20230726152258-mutt-send-email-mst@kernel.org> <3ae9e8919a9316d06d7bb507698c820ac6194f45.camel@nvidia.com> <20230727122633-mutt-send-email-mst@kernel.org> <20230731050200-mutt-send-email-mst@kernel.org> <39c3be5dd59e67e7b5dd301100e96aa9428bc332.camel@nvidia.com> <4375036868b636fa9c5a03e7fa9c4d7cdefefc5f.camel@nvidia.com> <5eba7bc2d3f253be4b0b998dc8a7a3efc7fe08d9.camel@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5eba7bc2d3f253be4b0b998dc8a7a3efc7fe08d9.camel@nvidia.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Thu, Aug 03, 2023 at 03:02:59PM +0000, Dragos Tatulea wrote: > On Wed, 2023-08-02 at 09:56 +0200, Dragos Tatulea wrote: > > On Wed, 2023-08-02 at 10:51 +0800, Jason Wang wrote: > > > On Tue, Aug 1, 2023 at 4:17 PM Dragos Tatulea wrote: > > > > > > > > On Tue, 2023-08-01 at 11:59 +0800, Jason Wang wrote: > > > > > On Mon, Jul 31, 2023 at 5:08 PM Michael S. Tsirkin > > > > > wrote: > > > > > > > > > > > > On Mon, Jul 31, 2023 at 07:15:31AM +0000, Dragos Tatulea wrote: > > > > > > > On Thu, 2023-07-27 at 12:28 -0400, Michael S. Tsirkin wrote: > > > > > > > > On Thu, Jul 27, 2023 at 04:02:16PM +0000, Dragos Tatulea wrote: > > > > > > > > > On Wed, 2023-07-26 at 15:26 -0400, Michael S. Tsirkin wrote: > > > > > > > > > > On Wed, Jul 26, 2023 at 10:07:38PM +0300, Dragos Tatulea > > > > > > > > > > wrote: > > > > > > > > > > > The ndev was accessed on shutdown without a check if it > > > > > > > > > > > actually > > > > > > > > > > > exists. > > > > > > > > > > > This triggered the crash pasted below. This patch simply > > > > > > > > > > > adds > > > > > > > > > > > a > > > > > > > > > > > check > > > > > > > > > > > before using ndev. > > > > > > > > > > > > > > > > > > > > > >  BUG: kernel NULL pointer dereference, address: > > > > > > > > > > > 0000000000000300 > > > > > > > > > > >  #PF: supervisor read access in kernel mode > > > > > > > > > > >  #PF: error_code(0x0000) - not-present page > > > > > > > > > > >  PGD 0 P4D 0 > > > > > > > > > > >  Oops: 0000 [#1] SMP > > > > > > > > > > >  CPU: 0 PID: 1 Comm: systemd-shutdow Not tainted 6.5.0- > > > > > > > > > > > rc2_for_upstream_min_debug_2023_07_17_15_05 #1 > > > > > > > > > > >  Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS > > > > > > > > > > > rel- > > > > > > > > > > > 1.13.0-0- > > > > > > > > > > > gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014 > > > > > > > > > > >  RIP: 0010:mlx5v_shutdown+0xe/0x50 [mlx5_vdpa] > > > > > > > > > > >  RSP: 0018:ffff8881003bfdc0 EFLAGS: 00010286 > > > > > > > > > > >  RAX: ffff888103befba0 RBX: ffff888109d28008 RCX: > > > > > > > > > > > 0000000000000017 > > > > > > > > > > >  RDX: 0000000000000001 RSI: 0000000000000212 RDI: > > > > > > > > > > > ffff888109d28000 > > > > > > > > > > >  RBP: 0000000000000000 R08: 0000000d3a3a3882 R09: > > > > > > > > > > > 0000000000000001 > > > > > > > > > > >  R10: 0000000000000000 R11: 0000000000000000 R12: > > > > > > > > > > > ffff888109d28000 > > > > > > > > > > >  R13: ffff888109d28080 R14: 00000000fee1dead R15: > > > > > > > > > > > 0000000000000000 > > > > > > > > > > >  FS:  00007f4969e0be40(0000) GS:ffff88852c800000(0000) > > > > > > > > > > > knlGS:0000000000000000 > > > > > > > > > > >  CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > > > > > > > > > > >  CR2: 0000000000000300 CR3: 00000001051cd006 CR4: > > > > > > > > > > > 0000000000370eb0 > > > > > > > > > > >  DR0: 0000000000000000 DR1: 0000000000000000 DR2: > > > > > > > > > > > 0000000000000000 > > > > > > > > > > >  DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: > > > > > > > > > > > 0000000000000400 > > > > > > > > > > >  Call Trace: > > > > > > > > > > >   > > > > > > > > > > >   ? __die+0x20/0x60 > > > > > > > > > > >   ? page_fault_oops+0x14c/0x3c0 > > > > > > > > > > >   ? exc_page_fault+0x75/0x140 > > > > > > > > > > >   ? asm_exc_page_fault+0x22/0x30 > > > > > > > > > > >   ? mlx5v_shutdown+0xe/0x50 [mlx5_vdpa] > > > > > > > > > > >   device_shutdown+0x13e/0x1e0 > > > > > > > > > > >   kernel_restart+0x36/0x90 > > > > > > > > > > >   __do_sys_reboot+0x141/0x210 > > > > > > > > > > >   ? vfs_writev+0xcd/0x140 > > > > > > > > > > >   ? handle_mm_fault+0x161/0x260 > > > > > > > > > > >   ? do_writev+0x6b/0x110 > > > > > > > > > > >   do_syscall_64+0x3d/0x90 > > > > > > > > > > >   entry_SYSCALL_64_after_hwframe+0x46/0xb0 > > > > > > > > > > >  RIP: 0033:0x7f496990fb56 > > > > > > > > > > >  RSP: 002b:00007fffc7bdde88 EFLAGS: 00000206 ORIG_RAX: > > > > > > > > > > > 00000000000000a9 > > > > > > > > > > >  RAX: ffffffffffffffda RBX: 0000000000000000 RCX: > > > > > > > > > > > 00007f496990fb56 > > > > > > > > > > >  RDX: 0000000001234567 RSI: 0000000028121969 RDI: > > > > > > > > > > > fffffffffee1dead > > > > > > > > > > >  RBP: 00007fffc7bde1d0 R08: 0000000000000000 R09: > > > > > > > > > > > 0000000000000000 > > > > > > > > > > >  R10: 0000000000000000 R11: 0000000000000206 R12: > > > > > > > > > > > 0000000000000000 > > > > > > > > > > >  R13: 00007fffc7bddf10 R14: 0000000000000000 R15: > > > > > > > > > > > 00007fffc7bde2b8 > > > > > > > > > > >   > > > > > > > > > > >  CR2: 0000000000000300 > > > > > > > > > > >  ---[ end trace 0000000000000000 ]--- > > > > > > > > > > > > > > > > > > > > > > Fixes: bc9a2b3e686e ("vdpa/mlx5: Support interrupt > > > > > > > > > > > bypassing") > > > > > > > > > > > Signed-off-by: Dragos Tatulea > > > > > > > > > > > --- > > > > > > > > > > >  drivers/vdpa/mlx5/net/mlx5_vnet.c | 3 ++- > > > > > > > > > > >  1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > > > > > > > > > > > > > > > > > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c > > > > > > > > > > > b/drivers/vdpa/mlx5/net/mlx5_vnet.c > > > > > > > > > > > index 9138ef2fb2c8..e2e7ebd71798 100644 > > > > > > > > > > > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c > > > > > > > > > > > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c > > > > > > > > > > > @@ -3556,7 +3556,8 @@ static void mlx5v_shutdown(struct > > > > > > > > > > > auxiliary_device > > > > > > > > > > > *auxdev) > > > > > > > > > > >         mgtdev = auxiliary_get_drvdata(auxdev); > > > > > > > > > > >         ndev = mgtdev->ndev; > > > > > > > > > > > > > > > > > > > > > > -       free_irqs(ndev); > > > > > > > > > > > +       if (ndev) > > > > > > > > > > > +               free_irqs(ndev); > > > > > > > > > > >  } > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > something I don't get: > > > > > > > > > > irqs are allocated in mlx5_vdpa_dev_add > > > > > > > > > > why are they not freed in mlx5_vdpa_dev_del? > > > > > > > > > > > > > > > > > > > That is a good point. I will try to find out. I also don't get > > > > > > > > > why > > > > > > > > > free_irq > > > > > > > > > is > > > > > > > > > called in the vdpa dev .free op instead of mlx5_vdpa_dev_del. > > > > > > > > > Maybe I > > > > > > > > > can > > > > > > > > > change > > > > > > > > > that in a different refactoring. > > > > > > > > > > > > > > > > as it is I have no idea whether e.g. ndev can change > > > > > > > > between these two call sites. that would make the check > > > > > > > > pointless. > > > > > > > > > > > > > > > > > > this is what's creating all this mess. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Not quite: mlx5_vdpa_dev_del (which is a .dev_del of for struct > > > > > > > > > vdpa_mgmtdev_ops) doesn't get called on shutdown. At least > > > > > > > > > that's > > > > > > > > > what > > > > > > > > > I > > > > > > > > > see. Or > > > > > > > > > am I missing something? > > > > > > > > > > > > > > > > and why do we care whether irqs are freed on shutdown? > > > > > > > > > > > > > > > Had to ask around a bit to find out the answer: there can be issues > > > > > > > with > > > > > > > kexec > > > > > > > IRQ allocation on some platforms. It is documented here [0] for > > > > > > > mlx5_core. > > > > > > > > > > > > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/mellanox/mlx5/core/main.c#n2129 > > > > > > > > > > > > > > Thanks, > > > > > > > Dragos > > > > > > > > > > > > It's quite weird. > > > > > >          * Some platforms requiring freeing the IRQ's in the shutdown > > > > > >          * flow. If they aren't freed they can't be allocated after > > > > > >          * kexec. There is no need to cleanup the mlx5_core software > > > > > >          * contexts. > > > > > > > > > > > > but most drivers don't have a shutdown callback how do they work then? > > > > > > do you know which platforms these are? > > > > > > > > > I don't. x86_64 is not one of them though. I will do some more digging ... > > > > > > Turns out that this fix (releasing the irqs on .shutdown on mlx5_core) was > > required for PPC arch but only for certain mainframe systems. That's all the > > info I could find. > > > I will send a v2 for this patch that removes the shutdown op. The irqs will be > released by the mlx5_core shutdown handler which is responsible for the VF. > > Thanks, > Dragos Certainly seems cleaner. Thanks! > > > > > There used to be bzs that requires virtio drivers to add a shutdown to > > > > > fix kexec: > > > > > > > > > > https://bugzilla.redhat.com/show_bug.cgi?id=2108406 > > > > > > > > > I don't have access to this. What is it about? > > > > > > This bug might be more accurate: > > > > > > https://bugzilla.redhat.com/show_bug.cgi?id=1820521 > > > > > > It's about the kexec guys (cced relevant people) wanting to add a > > > shutdown method for virito to fix potential kexec issues. > > > > > > Thanks > > > > > > > > > > > Thanks, > > > > Dragos > > > > > Thanks > > > > > > > > > > > > > > > > > I don't really know much about why shutdown callback is even > > > > > > necessary. > > > > > > I guess this is to detect shutdown and do a faster cleanup than > > > > > > the slow, graceful removal, just cleaning hardware resources? > > > > > > > > .shutdown could be removed in mlx5_vdpa. But I notice that mlx5_core's > > .shutdown > > kicks in from pci_device_shutdown to clean the irqs. So the irqs will still be > > freed but as a side effect. Which is not good. > > > > Thanks, > > Dragos >