From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E06C1413226 for ; Wed, 13 May 2026 12:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778675654; cv=none; b=np7d6xRkLNn3wNYYzJFdKQbRo72CMrAYA0nqyYihSwktbYkk/Uoxb0jxKy4M5DiYiFrG6aJUCXVkKDCdrC1IuSDqkX2d7lP6LwV6PlYE2O3MYCAwLASgADukV0D9McRt+EljteZvZphf2VEq4qROSzK5puI6Kl/2/N+9SRnrrVs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778675654; c=relaxed/simple; bh=NL+0hN7dcmk6reTk4fWsx9HcPciA4cyloazqc/q7UAE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tZwZxw7wSzXa9ZX+wOtvLAX2fIW6doD2ZBJpdPOhO+5JMVn/cbKhv6ERISf6FMB38u1qBTdmsrlhW9a6csuzlbm0g5fac0yxldfuWO9AESTnZSVqopX/8poQ5bWaEUZuBqgvxAW9uUsQ8bTIEGcD5phZiQcF2QKykMb+D83PPDA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=X+6mQgBK; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=KQul7vk7; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="X+6mQgBK"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="KQul7vk7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778675652; 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=+TQYbXlymtDPWPBG8UfeNdlqdxdWRntP15VStFgg3bs=; b=X+6mQgBKuX6mYkgaQ4GMu3vGxuEL8qSGLZFDslu9WOClTUxeOTguK+TjOAgh/6TNCXk3kV xDq+ddoO9JnDrWn8Wgtd5+FpEA4qw83MxP2oZ75Smelb0DQAiCMggkjeHfKQG6V8otphhX 62ssOe3RcxRopyFbWFFJlYhG+DZ3eqs= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-281-Ch91o7u3NA-Y5k5m7tF5AA-1; Wed, 13 May 2026 08:34:10 -0400 X-MC-Unique: Ch91o7u3NA-Y5k5m7tF5AA-1 X-Mimecast-MFC-AGG-ID: Ch91o7u3NA-Y5k5m7tF5AA_1778675649 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-43efc93e4f6so4427189f8f.3 for ; Wed, 13 May 2026 05:34:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778675649; x=1779280449; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=+TQYbXlymtDPWPBG8UfeNdlqdxdWRntP15VStFgg3bs=; b=KQul7vk7gnprAc7o8Q3+gzsCrfnHiqDNRSnTvHRCxMlPZub5CGxM25awlN884eTyV9 JlcQo4PrCgQ2LGPZcmReJoTLXgWZdMYaVAS44c1/wFP5/ZxqLmbsFK7RMNOEx21LjTC1 7MGLOq5JY2X0ASViZkTs8t6rNRDN54uLkzBcH2q3enIuxMRrXw65yoJMk9waj7lvm4Y0 7naULKpLKW0m7ZLb1wXEYJXldzGi+wf4UhP1tu5g1PTkrMw8xcF1PzD+RKHQJWlYjjvr PEOF635ZJ8Y13JUE8Z2Jc6Lc76Pph/XC+QgGwPue3NM5s54pIynqfpvtnovWCqOPlo5a FBSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778675649; x=1779280449; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+TQYbXlymtDPWPBG8UfeNdlqdxdWRntP15VStFgg3bs=; b=lfsGhD+wpLqzQR2+pGEiyOroEIaUYiyAD1aF/GJ9aMsFehMEP8pJvh4IaW/kDvapGT cWqTi2GxOOw7Zhu7RL8AGd8/h2m3JLt2m8/y+2auc85L7yQczjq4hIdAPBvgsmpySs/P kuLVm/fNQdJ5SCymlbB6uz7Zo2Yz5jkp4SILuIiqYQfXLEN87OY6U+07hRv8DVvgYqYD WvJQQGnppbF0Dqf9Ngpln4WpKz3LCoP0TiJXklGfIzHUEyLZyMKehaiQBQJT9pTDJbXi bAka9v5WhJBziidx8sCJQntz2fvsAfORRkiH0O++jshO8HO7h4v0boF/tyNODdgswXrQ xsnw== X-Forwarded-Encrypted: i=1; AFNElJ+J6SZENpYND+w65WsJVCYTEvXNNOwx1GkP1eQ2GmV3zoKEUeHdqX5ikKJxnHBQbfz2Le5Wl50uA3Y6Sg4=@vger.kernel.org X-Gm-Message-State: AOJu0Yw6BqhDz2C5HgVtcyzxRkxN96cut+fIm/sJC6ewED72s43ygW7/ ikcPKmQnDk3koFHYheQuvst3I9aUULYCLqe1J8vuDIvdi0mJQpWLiXaXhOGljiZBGtfuUkuj7nn FRr7YX/Huodq8D9vvifYge74ZNDm6MnxyGP4kZFS7YMAGy9sewh86qKFmH6mN5Hv9Gw== X-Gm-Gg: Acq92OG+UuQIki7o5drvzD3K4N8knWKMeEUUyB/rnf0yJMEN09UYiisRaI+T/q9cDP4 i7sUUCmHuA2h8TObPnob4N/IFcPpCV08/eX8OBMJq1UgjPCttkZzvcUB3uh3X77IBbXnIp4VBBg fbUqjW9MOPuLi/0IJm3QM5vsEwUOUKAzDK0TgahbtvL8yKUKwx0ka6MbprigstXpFfKIpnuHSBl 4PCjzNJ5UOiyz06i58rOlf6c8StKqQlTTp5vUucmsm/Gm/oYjXQFZDQU4c6b2DGKtTtJhOjuT+a 53WPTCsYgEDgWBGAHuCmMkaENP0QS1MdxvvjmzTabIbGIs1RjTNDLmcdqIsHecYP64BBmkaDHUb Einrw6Ur4qfjhgG87KG2VozcK2SSz4szZvyieDlrC X-Received: by 2002:a5d:5d87:0:b0:441:1c18:f779 with SMTP id ffacd0b85a97d-45c59cce4demr5115651f8f.37.1778675649246; Wed, 13 May 2026 05:34:09 -0700 (PDT) X-Received: by 2002:a5d:5d87:0:b0:441:1c18:f779 with SMTP id ffacd0b85a97d-45c59cce4demr5115580f8f.37.1778675648751; Wed, 13 May 2026 05:34:08 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4548ec6c221sm41530491f8f.13.2026.05.13.05.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2026 05:34:08 -0700 (PDT) Date: Wed, 13 May 2026 08:34:05 -0400 From: "Michael S. Tsirkin" To: Jinhui Guo Cc: David Laight , Eugenio =?iso-8859-1?Q?P=E9rez?= , Jason Wang , Jiri Pirko , Xuan Zhuo , linux-kernel@vger.kernel.org, stable@vger.kernel.org, virtualization@lists.linux.dev Subject: Re: [PATCH] virtio_pci_modern: Use GFP_ATOMIC with spin_lock_irqsave held in virtqueue_exec_admin_cmd() Message-ID: <20260513083332-mutt-send-email-mst@kernel.org> References: <20260413101759.6323fb68@pumpkin> <20260413122244.534-1-guojinhui.liam@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260413122244.534-1-guojinhui.liam@bytedance.com> On Mon, Apr 13, 2026 at 08:22:44PM +0800, Jinhui Guo wrote: > On Mon, Apr 13, 2026 at 10:17:59 +0100, David Laight wrote: > > Or do the allocate before acquiring the lock (and free it not used > > in the error path). > > Hi David, > > Thanks for the suggestion. > > Pre-allocating the memory outside the lock is indeed a good practice, > but unfortunately it doesn't work in this specific virtqueue context. > > The kmalloc() in question is not happening at the virtqueue_exec_admin_cmd() > level. Instead, it is deeply embedded inside virtqueue_add_sgs() > (specifically, in functions like alloc_indirect_split() or > virtqueue_add_indirect_packed()) to allocate indirect descriptors when > multiple SG elements are provided. > > As a caller, we have no mechanism to pre-allocate this indirect descriptor > memory and pass it down to virtqueue_add_sgs(). Furthermore, virtqueue_add_sgs() > needs to atomically check the queue's num_free status, allocate the indirect > table if necessary, and update the queue pointers. All these operations > must be protected by admin_vq->lock to prevent concurrent admin command > submissions from corrupting the virtqueue state. > > Therefore, allocating before acquiring the lock isn't feasible here, and > replacing GFP_KERNEL with GFP_ATOMIC (with a proper sleepable retry upon > failure) seems to be the more viable fix. > > Does this make sense? > > Thanks, > Jinhui it might be quite ok. what is missing is the analysis of whether we can actually get this error and what happens then.