Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp3013438ybx; Sun, 3 Nov 2019 08:49:07 -0800 (PST) X-Google-Smtp-Source: APXvYqy8nCII/FSDhcQLrMIIsOAmZ7ZSdYWhqH2TlCEr8aaVUkzJh6YrOuyFev4FeOkt3dDD7Npx X-Received: by 2002:a17:906:7212:: with SMTP id m18mr19917796ejk.88.1572799747622; Sun, 03 Nov 2019 08:49:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572799747; cv=none; d=google.com; s=arc-20160816; b=N9bn4RJdeLOUXPoqAYkiHLIamuAJ8EOAAfkKNwZlPdcojsWsj9/zNkt1zO+QDmpFUJ AIuSYIuf0UjqDawYwYDeI5MsaXi9ZMG+xu67Ov1KhJ3aCvn/CbuCbObfl2cdgav0ZFzg +QJD1MxyhsHz3rtvv6cqf9fjSWiIrNl5ORg6RR0xberA3oj+H4a9Auhv66XtS8153NXE sXyNz77GwYDQqq6ZKv8+eTKGN6fM7NFmeNg3QCRT9pCLWA8HSCZZ9BfvUUv0geLTzHh/ M/4wpPVREZ1NZsZA4NhTff8WKCa7JzBni/2NcfKaJqhZBY0CbEAaxQOy3JzMR2pvdWVS WJ1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ksEu0A0KjLwy1M0pwU6CUlXpOlz1Dc+D61V1TG3xX/c=; b=UPfhqVTmcWxZSN/RxW/LHsXhQJii4eKT486Mi9fTEJvLAOonfA4Ll7DZonyoNM5bgu CHc3q/gNs4zCodtRNphnsITkQxWIXozcXFqbHp8YVFiAFryKsfG9b8nK8uLP7OBB+8JZ Qzoc26vuJGyyF2d44LSz4F+K96ODG+5C6LvF4xtxxmMeH5StPsQvvFp/8dJmg/Zkjb5F Iie7CEx2+QO49vFixOpOKsRwiJZ3RJcA9ilmKDDMCS4mNIAQShGqSt67VvOzxFuT+J0+ Bdd1dlxH1XAyP2XlD8EQvNNA5NeLujZ2bTF2m62GCbYQ5fQVeesSCP46HMEAo1jErjkv P+MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Puv7vmSp; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11si5643169edb.100.2019.11.03.08.48.40; Sun, 03 Nov 2019 08:49:07 -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=@linux-foundation.org header.s=google header.b=Puv7vmSp; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727826AbfKCQpq (ORCPT + 99 others); Sun, 3 Nov 2019 11:45:46 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:43109 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727717AbfKCQpp (ORCPT ); Sun, 3 Nov 2019 11:45:45 -0500 Received: by mail-lj1-f196.google.com with SMTP id y23so4128014ljh.10 for ; Sun, 03 Nov 2019 08:45:44 -0800 (PST) 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=ksEu0A0KjLwy1M0pwU6CUlXpOlz1Dc+D61V1TG3xX/c=; b=Puv7vmSp8hqtr7dTSpIERhXWbuCG6m92q8NpW8kfcLLCpTj2WmtgknmsiAhxP7lWV6 7+Vkeqs7gpDvpz9+OB1fTJzaOGKN3uQHkO587f1Z9kaGu38OIBzIX2T6wxkdCPz+6XAO iIYgAnhZTNw8f+CmIl6V01mf3+EqjV1hHwUwk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ksEu0A0KjLwy1M0pwU6CUlXpOlz1Dc+D61V1TG3xX/c=; b=BGZYcplok6kTjtjNCgtzAqjMk5Zt5XFuZh0mR79sfvrvu3tDdlTXeWb4nkh7xSAsVu 3cPPa+UQG2Mzlfq9SItvhdNj6j+LUyP0YFWc9+epnVdk6Ou7jxaAWuF3xaaxxer1V6gW u+v0Tt7x0m9ejQoU0cqzzz1TWeOzXjZGO0Yo71zl09WPN5AM70vFK7qLA+gthMAickPz NIuIIGo7f+L5/9NMZ6gJDg10TL+Fve7UvoWe2LR6L4zyBAH2ycXbRwHxOnbXq8cgPwi1 3JDsoO7cWwLnT4RcKt/Gtkz+A5RGcyKPsYlA8fD7B4BliCGHxJTPIP64mcfV6+0L3Uju mk1g== X-Gm-Message-State: APjAAAWWHqNiHSd0cEXXXxpoL43N04+Oz9h5AfIXwcc1hEXRirac7sOe tmBm2L1s5byZHrMYtyYwgltjow2lufo= X-Received: by 2002:a05:651c:305:: with SMTP id a5mr16010610ljp.144.1572799543255; Sun, 03 Nov 2019 08:45:43 -0800 (PST) Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com. [209.85.167.45]) by smtp.gmail.com with ESMTPSA id y189sm9284556lfc.9.2019.11.03.08.45.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Nov 2019 08:45:42 -0800 (PST) Received: by mail-lf1-f45.google.com with SMTP id v4so10463339lfd.11 for ; Sun, 03 Nov 2019 08:45:41 -0800 (PST) X-Received: by 2002:ac2:4c86:: with SMTP id d6mr13812625lfl.106.1572799541430; Sun, 03 Nov 2019 08:45:41 -0800 (PST) MIME-Version: 1.0 References: <20191102190327.24903-1-alex.popov@linux.com> In-Reply-To: <20191102190327.24903-1-alex.popov@linux.com> From: Linus Torvalds Date: Sun, 3 Nov 2019 08:45:25 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 1/1] media: vivid: Fix wrong locking that causes race conditions on streaming stop To: Alexander Popov Cc: Hans Verkuil , Mauro Carvalho Chehab , Security Officers , Linux Media Mailing List , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Nov 2, 2019 at 12:03 PM Alexander Popov wrote: > > - mutex_lock(&dev->mutex); > + if (!mutex_trylock(&dev->mutex)) { > + schedule_timeout(1); > + continue; > + } > + I just realized that this too is wrong. It _works_, but because it doesn't actually set the task state to anything particular before scheduling, it's basically pointless. It calls the scheduler, but it won't delay anything, because the task stays runnable. So what you presumably want to use is either "cond_resched()" (to make sure others get to run with no delay) or "schedule_timeout_uninterruptible(1)" which actually sets the process state to TASK_UNINTERRUPTIBLE. The above works, but it's basically nonsensical. My bad for not noticing earlier. Linus