Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2367768imu; Mon, 17 Dec 2018 00:14:15 -0800 (PST) X-Google-Smtp-Source: AFSGD/V8DYSATEbY/bT7aVUnYKXptKp8fIeUVYElz0UB3kVEj23XevajgumgyXQnahzJCcxGht6q X-Received: by 2002:a17:902:6b49:: with SMTP id g9mr11653527plt.98.1545034455935; Mon, 17 Dec 2018 00:14:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545034455; cv=none; d=google.com; s=arc-20160816; b=e+i+ov9//sxCMiCFKYxOY8NPAOSo4yZqMKFnLz+V3NMQLzH/ero3Sbt4C60K7wjTsn fw+jnJYBfyRYvRRFA8m/IaEiyI0+Y8LfegnqISacJGGEHaS2ayHkE7Irb/yEtLz5RPQ7 KytaOBxeKO4HRYKbGy1QNJyOErYFCOzgOCdy8n/YfNCZ0TE9HiRvZJlUHJafVPPcByAx FWjWHpEh8BpvfllJALt2CIxDAoHvJBsCA8GIVTK4M3d07o2fl3DtgDW0pcP/V21X6jDp BoW1MMmtsK+U+a4Dk6ytO5IFNDsj7fCFIzSePq/CHU0podNR31opiqPZYJhh9jU1lslV /JWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature; bh=Ee9i0Pf5EL3wAgyVdNMbOnVA/LU9ZoEU3jWh4MH/pzM=; b=jy5AAnMZpPlngjYyhDPVWKUdWXqI3b6bkL+H4+pj8DapYXmJe7n8qImdSVCry8/yGL xkED5zJBE7QmjgM9KYS+lkVpeY+1vyKMO1sn3dIg5tyW80WT49p6Ow+D5ky0EfEGrkLg zNRM3XT2FY3OrRwc+8iRtK+kUsHaLWV8aj8rHvENF2FyiEwxrtWpAhFMgbi2h0AB1xBv eGZG3Ktxx1KY8hXzPke3FkAKgG3GWtJnBw4da0lXOZsk5SX77W3xL1D1htYsc9udu2TB UTYdje4tKKdpWRT2In1ia7AAv10/WTDphypVHvjDC+xTNdhhs0Bnyu7ahZ9k/Vjb3jsJ VtSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TpkN5UV+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i35si10439326plg.396.2018.12.17.00.14.01; Mon, 17 Dec 2018 00:14:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TpkN5UV+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731479AbeLQHhv (ORCPT + 99 others); Mon, 17 Dec 2018 02:37:51 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:43018 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726488AbeLQHhu (ORCPT ); Mon, 17 Dec 2018 02:37:50 -0500 Received: by mail-lj1-f195.google.com with SMTP id 83-v6so10030756ljf.10; Sun, 16 Dec 2018 23:37:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Ee9i0Pf5EL3wAgyVdNMbOnVA/LU9ZoEU3jWh4MH/pzM=; b=TpkN5UV+4R+3lM37Too5v1z/85hmIGavnvKP/gg9I398N19V7mS6+NE23DUx7M/TR5 Dh17pzlGEo/ItMWIu8Xe7pvkB2HFUuleGZzYtBJKOA8pwMLIV1/tohVXhZ8VtHWpl5/O rW05YlOAnumFpPmNIqOtPpVFI199qW/72bJQGX35hXFqa0FzMQFE6vePEpnfguK/YH7N EbJceUn8dd0aBKSvv7SqP2FNbdzsKtwkejFz04kpYoHc/sdtOkAQpSC4jcN3m/oZELWG SOh1g2GKvB6L5DSbfIvAIkKiC15I838n6gPs6bxUs+VCQSkbi2hGJchsfqOmFNKAw6v4 Dq0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=Ee9i0Pf5EL3wAgyVdNMbOnVA/LU9ZoEU3jWh4MH/pzM=; b=Eot+WLGlMPuuT1czzJyq4OxDSKzv4F3g1nytMuo6mmvzUCFzYHKnIrPrnAv5YuFaN7 fBd9e4M2k7FEyX45+GE/bf6H9z8MT+Fgg2qP49RMNFSAVzV5ZBMlWXJWk/HxUMHLoock B8snasfMUoyYAhuPR1QiGbkiM/Vc2mvCX7bhPRFk3x7ycfGOqL5YwgGf924UikYHtPRa 8KlYMnDSmXpFKOqlebtxXN92KKsrDi1KhNJPgZArV66n8JfYHFZeTH89CmFbnZ66eAfW xS/5G97JR9zIRZAO7F7KcQCenX5LjaLJPj3OWJKAi6VmrhBvjhHMUhQ8DDdUbGFWyI8E KTLA== X-Gm-Message-State: AA+aEWYu7daAB+QVIgiIuJEXLSFYHMC+h3kEZzO5KQYdpt5BrPE8A26t 8qi9npQmaIScrvNHQ3y7ecIty9VrQDI= X-Received: by 2002:a2e:9957:: with SMTP id r23-v6mr6407949ljj.98.1545032267467; Sun, 16 Dec 2018 23:37:47 -0800 (PST) Received: from [192.168.0.21] (87-50-154-159-cable.dk.customer.tdc.net. [87.50.154.159]) by smtp.gmail.com with ESMTPSA id h22-v6sm2410703ljg.24.2018.12.16.23.37.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Dec 2018 23:37:47 -0800 (PST) Subject: Re: [PATCH 1/3] 9p/net: implement asynchronous rpc To: Dominique Martinet , v9fs-developer@lists.sourceforge.net Cc: Dominique Martinet , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Van Hensbergen , Latchesar Ionkov , Dmitry Vyukov References: <1544532108-21689-1-git-send-email-asmadeus@codewreck.org> From: Tomas Bortoli Openpgp: preference=signencrypt Autocrypt: addr=tomasbortoli@gmail.com; prefer-encrypt=mutual; keydata= mQINBFpCTZMBEADNZ1+Ibh0Z4pgGRcd1aOUMbe/YfHktmajjcoTnKmZZunjoUVAl8waeLITd BC2c8i1wHzHcnthrmb1izs5XlG6PZnl8n5tjysSNbwggzS1NcEK1qgn5VjNlHQ5aRMUwCC51 kicBiNmlQk2UuzzWwdheRGnaf+O1MNhC0GBeEDKQAL5obOU92pzflv6wWNACr+lHxdnpyies mOnRMjH16NjuTkrGbEmJe+MKp0qbjvR3R/dmFC1wczniRMQmV5w3MZ/N9wRappE+Atc1fOM+ wP7AWNuPvrKg4bN5uqKZLDFH7OFpxvjgVdWM40n0cQfqElWY9as+228Sltdd1XyHtUWRF2VW O1l5L0kX0+7+B5k/fpLhXqD3Z7DK7wRXpXmY59pofk7aFdcN97ZK+r6R7mqrwX4W9IpsPhkT kUyg3/Dx/khBZlJKFoUP325/hoH684bSiPEBroel9alB7gTq2ueoFwy6R3q5CMUw3D+CZWHA 3xllu46TRQ/Vt2g0cIHQNPoye2OWYFJ6kSEvaLpymjNDJ9ph2EuHegonDfOaYSq34ic2BcdB JkCgXRLP5K7KtRNJqqR+DM8xByeGmQv9yp6S97el+SiM9R53RhHawJZGz0EPl+2Q6+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39wGjfC2+PM5I0xebbxtnuTewRchVVfm7UWgLAy11pV3xM4wMSJOuqVMOz jYpWKYxDTpvsZ0ginUUY993Gb8k/CxjABEMUGVHhQPZ0OzjHIKS6cTzN6ue8bB+CGOLCaQp1 C0NRT5Tn9zpLxtf5nBExFd/zVENY5vAV2ZbKQdemO54O7j6B9DSgVRrm83GCZxbL4d+qTYBF 3tSCWw/6SG1F3q9gR9QrSC2YRjCmhijUVEh6FhZwB58TNZ1sEEttrps8TDa5tUd9 Message-ID: <39a3c5f8-6cb6-c1cf-d10f-674e3244daee@gmail.com> Date: Mon, 17 Dec 2018 08:37:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <1544532108-21689-1-git-send-email-asmadeus@codewreck.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hey Dominique, sorry for the delay, I've been quite busy these days. The patches looks good to me and should indeed speed up the code a bit. I quickly tested them against Syzkaller tuned for the 9p subsystem and everything seems fine. And by the way, which refcount races? Cheers, Tomas On 12/11/18 1:41 PM, Dominique Martinet wrote: > From: Dominique Martinet > > Add p9_client_async_rpc that will let us send an rpc without waiting > for the reply, as well as an async handler hook. > > The work done in the hook could mostly be done in the client callback, > but I prefered not to for a couple of reasons: > - the callback can be called in an IRQ for some transports, and the > handler needs to call p9_tag_remove which takes the client lock that has > recently been reworked to not be irq-compatible (as it was never taken > in IRQs until now) > - the handled replies can be handled anytime, there is nothing the > userspace would care about and want to be notified of quickly > - the async request list and this function would be needed anyway for > when we disconnect the client, in order to not leak async requests that > haven't been replied to > > Signed-off-by: Dominique Martinet > Cc: Eric Van Hensbergen > Cc: Latchesar Ionkov > Cc: Tomas Bortoli > Cc: Dmitry Vyukov > --- > > I've been sitting on these patches for almost a month now because I > wanted to fix the cancel race, but I think it's what the most recent > syzbot email is about so if it could find it without this it probably > won't hurt to at least get some reviews for these three patches first. > > I won't submit these for next cycle, so will only put them into -next > after 4.20 is released; hopefully I'll have time to look at the two > pending refcount races around that time. > Until then, comments please! > > > include/net/9p/client.h | 9 +++++- > net/9p/client.c | 64 +++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 72 insertions(+), 1 deletion(-) > > diff --git a/include/net/9p/client.h b/include/net/9p/client.h > index 947a570307a6..a4ded7666c73 100644 > --- a/include/net/9p/client.h > +++ b/include/net/9p/client.h > @@ -89,7 +89,8 @@ enum p9_req_status_t { > * @tc: the request fcall structure > * @rc: the response fcall structure > * @aux: transport specific data (provided for trans_fd migration) > - * @req_list: link for higher level objects to chain requests > + * @req_list: link used by trans_fd > + * @async_list: link used to check on async requests > */ > struct p9_req_t { > int status; > @@ -100,6 +101,7 @@ struct p9_req_t { > struct p9_fcall rc; > void *aux; > struct list_head req_list; > + struct list_head async_list; > }; > > /** > @@ -110,6 +112,9 @@ struct p9_req_t { > * @trans_mod: module API instantiated with this client > * @status: connection state > * @trans: tranport instance state and API > + * @fcall_cache: kmem cache for client request data (msize-specific) > + * @async_req_lock: protects @async_req_list > + * @async_req_list: list of requests waiting a reply > * @fids: All active FID handles > * @reqs: All active requests. > * @name: node name used as client id > @@ -125,6 +130,8 @@ struct p9_client { > enum p9_trans_status status; > void *trans; > struct kmem_cache *fcall_cache; > + spinlock_t async_req_lock; > + struct list_head async_req_list; > > union { > struct { > diff --git a/net/9p/client.c b/net/9p/client.c > index 357214a51f13..0a67c3ccd4fd 100644 > --- a/net/9p/client.c > +++ b/net/9p/client.c > @@ -729,6 +729,62 @@ static struct p9_req_t *p9_client_prepare_req(struct p9_client *c, > return ERR_PTR(err); > } > > +static struct p9_req_t * > +p9_client_async_rpc(struct p9_client *c, int8_t type, const char *fmt, ...) > +{ > + va_list ap; > + int err; > + struct p9_req_t *req; > + > + va_start(ap, fmt); > + req = p9_client_prepare_req(c, type, c->msize, fmt, ap); > + va_end(ap); > + if (IS_ERR(req)) > + return req; > + > + err = c->trans_mod->request(c, req); > + if (err < 0) { > + /* bail out without flushing... */ > + p9_req_put(req); > + p9_tag_remove(c, req); > + if (err != -ERESTARTSYS && err != -EFAULT) > + c->status = Disconnected; > + return ERR_PTR(safe_errno(err)); > + } > + > + return req; > +} > + > +static void p9_client_handle_async(struct p9_client *c, bool free_all) > +{ > + struct p9_req_t *req, *nreq; > + > + /* it's ok to miss some async replies here, do a quick check without > + * lock first unless called with free_all > + */ > + if (!free_all && list_empty(&c->async_req_list)) > + return; > + > + spin_lock_irq(&c->async_req_lock); > + list_for_each_entry_safe(req, nreq, &c->async_req_list, async_list) { > + if (free_all && req->status < REQ_STATUS_RCVD) { > + p9_debug(P9_DEBUG_ERROR, > + "final async handler found req tag %d type %d status %d\n", > + req->tc.tag, req->tc.id, req->status); > + if (c->trans_mod->cancelled) > + c->trans_mod->cancelled(c, req); > + /* won't receive reply now */ > + p9_req_put(req); > + } > + if (free_all || req->status >= REQ_STATUS_RCVD) { > + /* Put old refs whatever reqs actually returned */ > + list_del(&req->async_list); > + p9_tag_remove(c, req); > + } > + } > + spin_unlock_irq(&c->async_req_lock); > +} > + > /** > * p9_client_rpc - issue a request and wait for a response > * @c: client session > @@ -746,6 +802,8 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...) > unsigned long flags; > struct p9_req_t *req; > > + p9_client_handle_async(c, 0); > + > va_start(ap, fmt); > req = p9_client_prepare_req(c, type, c->msize, fmt, ap); > va_end(ap); > @@ -841,6 +899,8 @@ static struct p9_req_t *p9_client_zc_rpc(struct p9_client *c, int8_t type, > unsigned long flags; > struct p9_req_t *req; > > + p9_client_handle_async(c, 0); > + > va_start(ap, fmt); > /* > * We allocate a inline protocol data of only 4k bytes. > @@ -1030,6 +1090,8 @@ struct p9_client *p9_client_create(const char *dev_name, char *options) > memcpy(clnt->name, client_id, strlen(client_id) + 1); > > spin_lock_init(&clnt->lock); > + spin_lock_init(&clnt->async_req_lock); > + INIT_LIST_HEAD(&clnt->async_req_list); > idr_init(&clnt->fids); > idr_init(&clnt->reqs); > > @@ -1101,6 +1163,8 @@ void p9_client_destroy(struct p9_client *clnt) > > v9fs_put_trans(clnt->trans_mod); > > + p9_client_handle_async(clnt, 1); > + > idr_for_each_entry(&clnt->fids, fid, id) { > pr_info("Found fid %d not clunked\n", fid->fid); > p9_fid_destroy(fid); >