From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8D2941D233 for ; Fri, 24 Jul 2026 09:44:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886266; cv=none; b=Q3OgBSWGYsKWv3/iHsfUm39ZlZ8QBsW7cSVhnnthubMI5CvWW3t7PEblYmsihVXiWyvY4ylnwxSlBsMg5MJb+DHinxPVutGMLeUr+FvDnOoz3kGdPz32Dxsx5QiRKm6Y+3ybd5Xm3yu67JHzg92AfFi6AIjBN+oufBYjdzwiAXI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886266; c=relaxed/simple; bh=eMlyiqXZjmjDnaqiA9Beg57b9q4uHubEnNNZqn0tyTM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=JTRdwHbR/giwSKP09v7hZrwCSJcgaE5tmsxfJCF/fJ04AqldIYfw9Atp1vkTGQjmtoIGMBpaOytz8uzseSe9LYboFc7mjJAvoXcNIXrxjy8gRmO2xfaaXJn15a0qPMITSz++sbGD9kksg85P4E8z+UBJi9HXuUzWQH/QTVqpjlw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=h5oYk1zn; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="h5oYk1zn" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-c166f1bbeaeso41696266b.0 for ; Fri, 24 Jul 2026 02:44:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784886263; x=1785491063; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=zACxA3C6bQvdgy3UWB7mt1+4bltOYljsqgZV5imQp+M=; b=h5oYk1zn4nQYn50FZ5izpwxBC/z5J6A8vtLBfuP4PIaoG3aCGR3ptV5wFgUsbaU69L 6KsmEOsptsea5BypqjQtzy8CeMwV2B0Rj8x6+UTYVr6RgLLgu3uXq7QZr5H/au9gr/bn 2TUxAwrrOk4B1iE81rdDIY0DjbhPmwIpgBimjIVInN/KMlSGYp0BEojgRGZSGxcURAJJ bnLky4sYB3AoFxYTenpXpJGQAA1YXf0tYzsnbFB2Yt13y2EY+GPgZHCIDSs5zchyz5jY 5JWJknfG0rO6XbSdLxFK5l56nwp0/PCDFnQoRs1EopOd/EvA0aVgNVkyQHBCI864G5JQ iy1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784886263; x=1785491063; h=references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=zACxA3C6bQvdgy3UWB7mt1+4bltOYljsqgZV5imQp+M=; b=dJZS0cAZjeb7xy6wdqSyLIigC2MEi7VyluQG8VeygO2ijYwpFLkRCisDPdj/y8NNi/ +w15XKZ8lZpJGWg91+5nCO2/zGX81tBoz85BETayWooKApZ5JyU26ywRbQg3WYIbvZNl oZ50tTd2PuNWsfZEnv4v85CsHjKvcdieaf/sOjM1C/EpW9H2xeFRjChQE2f3mllBMBhM 6ggjhjAz9j5hI5doLuRlSCr1ew3Chf5mA8AtMJferf350DaEWm3H0TyicSiwBpv4AKuI nyfu9x+UFZzkHKQLp5Z3Kh3ZIvshkM+eN+o3zznnvFXSJY7vWQZP0Qv0zwOLZ2m9DdHP t+eQ== X-Forwarded-Encrypted: i=1; AHgh+RrPC/00a5comtPQjAsQOyevIGEFpstplvt/6/uLTH8cGK3ikJmaIOAU/hLm/BYY82zME5Xk1w9e2+YWWFs=@vger.kernel.org X-Gm-Message-State: AOJu0YzI9KD6KSrXnCrruk8TvD5hLrbcr7fPlxORpaHpLvm/u4ZK3Rm6 oW+mELVbt+vmLBC6AU1bUCOPkWA/mDwdvMTzEzyOrsBuZ1LfCE8MCOXJ X-Gm-Gg: AR+sD12OvTYCjOVUmxJAdi8NJ+Z2v7Cq9/335R6yGzoQECQPBQWAowr3aoTaN/oHGlD M0TSG2aTThFbe32GHKfRTpPllwVDuS6O+z5G3w/jeMYFofGTf8HbgzBr0JMz0DryzRGfuNwZvJ1 uUe0zu9Eh9F3USTGNXp3N4VjLYGpk30Qgr7z3z5m7l5/SNxVeMyJ5vP3kykp9zxLH91c2Jd2aTE INMd8fuyrw3ytxdI1JPfj1NmYSc6MQlf8skx9K2WsZChmDMj+LstzCK7fPZI9JEZ82EaFDHhEup yhS263u6i6dB0gM462JOj85kPdIIkkapsXtgKMnlZ7d6T4iZUkivXga7FIPJMyar0romQFUKK0S I91fSgFvykJ5HUv2vJp4y8ZJVAO5C3U+emKtZQXy75vb0UCZLDHzAKVWlkEWOo40auq57H5qucl R+QbpUqWF/DNgkUz1WfDSTaPEwFRJoPA== X-Received: by 2002:a17:906:7947:b0:c15:f4aa:f30e with SMTP id a640c23a62f3a-c1c50d1cf10mr261248166b.37.1784886262530; Fri, 24 Jul 2026 02:44:22 -0700 (PDT) Received: from localhost (c-85-228-45-68.bbcust.telenor.se. [85.228.45.68]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1c4835c4bdsm245383166b.16.2026.07.24.02.44.21 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jul 2026 02:44:22 -0700 (PDT) From: Eli Billauer To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, corbet@lwn.net, Eli Billauer Subject: [PATCH v3 1/7] char: xillybus: Improve control of execution flow with mutexes Date: Fri, 24 Jul 2026 11:42:56 +0200 Message-Id: <20260724094302.50761-2-eli.billauer@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260724094302.50761-1-eli.billauer@gmail.com> References: <20260724094302.50761-1-eli.billauer@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: This commit addresses two issues by using mutexes: (1) Add a mutex to protect the fifo_buf_order global variable. The purpose of this variable is avoid repeated failed calls to __get_free_pages() for allocating FIFO memory, when the chunk size was too big. However, if two drivers are initialized at the same time, fifo_init() may run in parallel, and fifo_buf_order may be reduced too much. This is a far-fetched scenario, now completely prevented by fifo_buf_order_mutex. (2) setup_channels() acquires process_in_mutex to prevent process_bulk_in() from accessing the xillyusb_dev struct. With correctly working hardware, process_bulk_in() is never called while setup_channels() runs, because the device has no reason to send data in that phase. The mutex ensures that process_bulk_in() does not touch the members that setup_channels() alters. There is no similar protection for data flow in the other direction, because during the setup process, the only outbound data is the BULK endpoint used for commands, and it remains untouched after its initial setup. Assisted-by: Deepseek:v4-pro Kimi:K2.6 ChatGPT:GPT-5.5 Claude:Sonnet-4.6 Signed-off-by: Eli Billauer --- Notes: Changes v2->v3: -- Add Assisted-by tag to description No change on v1->v2. drivers/char/xillybus/xillyusb.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xillyusb.c index 34e7ad3bcab3..a28e6416cb01 100644 --- a/drivers/char/xillybus/xillyusb.c +++ b/drivers/char/xillybus/xillyusb.c @@ -50,6 +50,7 @@ MODULE_LICENSE("GPL v2"); static const char xillyname[] = "xillyusb"; static unsigned int fifo_buf_order; +static DEFINE_MUTEX(fifo_buf_order_mutex); static struct workqueue_struct *wakeup_wq; #define USB_VENDOR_ID_XILINX 0x03fd @@ -375,6 +376,8 @@ static int fifo_init(struct xillyfifo *fifo, unsigned int log2_fifo_buf_size; + guard(mutex)(&fifo_buf_order_mutex); + retry: log2_fifo_buf_size = fifo_buf_order + PAGE_SHIFT; @@ -1943,6 +1946,9 @@ static int setup_channels(struct xillyusb_dev *xdev, struct xillyusb_channel *chan, *new_channels; int i; + /* Don't let process_bulk_in() run while we change the channels */ + guard(mutex)(&xdev->process_in_mutex); + chan = kzalloc_objs(*chan, num_channels); if (!chan) return -ENOMEM; -- 2.34.1